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 (MCSD) Certification Exam. Practice with flashcards and multiple choice questions. Master each topic with hints and insights. Achieve your certification goals!

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.


What do you utilize to create a new Task in C#?

  1. New Task(Action a)

  2. Task.Run(Action a)

  3. Task.Factory(Action a)

  4. Task.Execute(Action a)

The correct answer is: New Task(Action a)

To create a new Task in C#, the correct statement is using the Task constructor, which takes an Action delegate as a parameter. By utilizing the constructor with `new Task(Action a)`, you create an instance of the Task that will execute the specified action when started. It’s important to note that after creating the Task with the constructor, you must call the `Start()` method on that Task instance to begin its execution. This approach allows for finer control over the Task's lifecycle, as you can set up the Task without immediately executing it. Other methods such as `Task.Run(Action a)` provide a more simplified means of executing tasks asynchronously, but they do so without the requirement of explicitly starting the task. Instead, they queue the task to run on the default task scheduler immediately. Using `Task.Factory(Action a)` isn't valid as Task.Factory doesn’t directly accept an Action in that manner. Additionally, `Task.Execute(Action a)` is also incorrect as there is no method called Execute for the Task class; Task instances are meant to be started and managed through their methods rather than executing directly. Understanding these constructors and methods is crucial for effective task management and asynchronous programming in C#.