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.


In C#, how do you wait for a single Task among multiple Tasks to complete?

  1. Task.WaitAny(tasks)

  2. WaitAny(tasks)

  3. Task.WaitOne(tasks)

  4. Task.WaitForAny(tasks)

The correct answer is: Task.WaitAny(tasks)

The method to wait for a single Task among multiple Tasks to complete in C# is Task.WaitAny(tasks). This method is part of the Task class in the System.Threading.Tasks namespace and is designed specifically for this purpose. When you pass an array of Task objects to Task.WaitAny, the method will block the calling thread until any one of the tasks in the array completes. This allows for efficient management of multiple asynchronous operations, as the caller can proceed as soon as any single task finishes, without waiting for all to complete. This behavior is particularly useful in scenarios where you want to take action on the first task that completes, such as handling results or cancelling the others if only one result is needed. In contrast, the other options do not correctly represent the mechanism provided by the Task Parallel Library for waiting on tasks: - WaitAny(tasks) omits the Task class prefix and would result in a compilation error because there's no standalone WaitAny method in the current context. - Task.WaitOne(tasks) is a method associated with wait handles and is not applicable to Task objects, which means it doesn't provide the functionality needed to handle multiple tasks directly. - Task.WaitForAny(tasks) is also incorrect because it does not exist in the Task Parallel Library; the