Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

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

Prepare for your Microsoft Certified Solutions Developer (MCSD) exam with flashcards and multiple choice questions. Each question includes hints and explanations to help you succeed. Get ready for your exam!

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 can you wait for a Task to finish in C#?

  1. t.Wait()

  2. Task.Wait(t)

  3. WaitTask(t)

  4. Task.WaitFor(t)

The correct answer is: t.Wait()

In C#, to wait for a Task to complete, you can simply call the Wait method on the task instance itself. When you use t.Wait(), you are invoking the Wait method of the Task class on the specific task instance denoted by 't'. This method will block the calling thread until the Task has completed its execution, which is a straightforward and effective way to ensure that you do not proceed until the desired Task has finished. The other provided options do not reflect correct usage of the Task class in C#. Option B suggests using Task.Wait with an argument, which is not how the method is designed to be called; it only allows a call on an instance of a Task. Options C and D suggest methods that do not exist in the Task class, indicating a misunderstanding of the API. Therefore, using t.Wait() is the correct and recommended way to wait for a Task to finish in C#.