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

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?

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?

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.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Seekat

Seekat

Task.ContinueWith – Creates a continuation that executes asynchronously when the target Task
completes.The returned Task will not be scheduled for execution until the current task has completed,
whether it completes due to running to completion successfully, faulting due to an unhandled exception, or
exiting out early due to being canceled.
http://msdn.microsoft.com/en-us/library/dd270696.aspx

Mario

Mario

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.

Kyo

Kyo

“You need to ensure that the second operation is invoked only if the data processing operation
throws an unhandled exception.”

A ?

Jason

Jason

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