Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the Microsoft Certified Solutions Developer Test with flashcards and multiple choice questions. Each question comes with hints and explanations. Boost your confidence for the exam day!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How do you wait for multiple Tasks to complete in C#?

  1. Task.WaitAll(tasks)

  2. Task.Wait(tasks)

  3. WaitForAll(tasks)

  4. Task.WaitComplete(tasks)

The correct answer is: Task.WaitAll(tasks)

To wait for multiple tasks to complete in C#, the most effective approach is to use the method Task.WaitAll(tasks). This method takes an array of Task objects as its parameter and blocks the calling thread until all of the provided tasks have completed execution. Using Task.WaitAll is beneficial because it ensures that all tasks are accounted for, rather than just one. This is particularly useful in scenarios where you need to coordinate the completion of multiple asynchronous operations before proceeding further in your program. By waiting for all tasks to finish, you can ensure that you handle the results or any exceptions that may have occurred collectively. The other options provided are not valid methods in the context of waiting for multiple tasks. Task.Wait is designed to block the calling thread until a single Task completes, rather than handling multiple tasks. WaitForAll and WaitComplete are not recognized methods in the Task class in C#, making them invalid choices for this scenario. Hence, utilizing Task.WaitAll is the appropriate and correct choice to manage multiple tasks efficiently.