PrepAway - Latest Free Exam Questions & Answers

You need to ensure that the second operation is invoked only if the data processing operation throws an unhand

You use the Task.Run() method to launch a long-running data processing operation. The data
processing operation often fails in times of heavy network congestion.
If the data processing operation fails, a second operation must clean up any results of the first
operation.
You need to ensure that the second operation is invoked only if the data processing operation
throws an unhandled exception.
What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Create a TaskCompletionSource<T> object and call the TrySetException() method of the object.

B.
Create a task by calling the Task.ContinueWith() method.

C.
Examine the Task.Status property immediately after the call to the Task.Run() method.

D.
Create a task inside the existing Task.Run() method by using the AttachedToParent option.

6 Comments on “You need to ensure that the second operation is invoked only if the data processing operation throws an unhand

    1. Mario says:

      I dont get it… What about the “second operation is invoked ONLY IF the data processing operation throws an unhandled exception”, While Task.ContinueWith() continues even if it does not throws exceptions.




      0



      0
  1. Jason says:

    I think C is also correct, due to the fact that you can check to see if the status is “TaskStatus.Faulted” and then can continue with your next execution.

    However in Microsoft tests, it’s always about using the ‘Most Correct’ way. In this case a ContinueWith() will work fine as long as you use the following overide:

    ContinueWith(Action, Object);

    The second parameter being the TaskContinuationOptions.OnlyOnFaulted




    1



    0

Leave a Reply