PrepAway - Latest Free Exam Questions & Answers

What code should you use?

You have recently created a multithreaded application to manage Domain.com’s inventory system.
The fulfillment task has to be executed on a regular basis, while other tasks are performed in the application.
The task does not need any input to start.
You are required to create and start the fulfillment thread using the appropriate code.
What code should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
ThreadStart work = new ThreadStart(Fulfill);
Thread thFulfill = new Thread(work);

B.
ParameterizedThreadStart work = new ParameterizedThreadStart(Fulfill);
Thread thFulfill = new Thread(work);

C.
ThreadStart work = new ThreadStart(Fulfill);
Thread thFulfill = new Thread(work);
thFulfill.Start();

D.
ParameterizedThreadStart work = new ParameterizedThreadStart(Fulfill);
Thread thFulfill = new Thread(work);
thFulfill.Start();

Explanation:
This code creates a ThreadStart delegate that references the Fulfill method, creates a Thread object named thFulfill, and invokes the Start method to begin the thread execution.
Incorrect Answers:
A: You should not use the code that uses the ThreadStart delegate but does not call the Start method because you are required to create and start the fulfillment thread.
B: You should not use the code that uses the ParameterizedThreadStart delegate and does not call the Start method. You have to invoke the Start method to begin thread execution.
D: You should not use the code that uses the ParameterizedThreadStart delegate and calls the Start method. The ParameterizedThreadStart delegate is used to reference a method that takes a generic object as an argument and, in this scenario, the fulfill method takes no arguments

One Comment on “What code should you use?


Leave a Reply