How to handle unexpected errors in a Dataflow
-
Sunday, October 14, 2012 11:36 AM
I did implement handling of unexpected errors by using <someBlock>.Completion.ContinueWith():
Async Function DoWork() As Task Dim downLoader As New TransformBlock(Of String, String)(...) ... downLoader.Completion.ContinueWith(Sub(ant) HandleUnexpectedError(ant.Exception), TaskContinuationOptions.OnlyOnFaulted) ... End FunctionThe compiler gives me the warning: Because this call is not awaited, execution of the current method continues before the call is completed.Consider applying the Await operator to the result of the call.
I don't understand what I am supposed to Await on, when defining an continuation to handle errors.
The Dataflow, including error handling, seems to work fine.Am I doing something wrong here?
All Replies
-
Sunday, October 14, 2012 2:53 PM
The warning tells you that you are ignoring the Task that is returned from ContinueWith(). Because there is no reason to use that Task for anything in your case, you can safely ignore that warning.- Marked As Answer by pmeinl Tuesday, October 16, 2012 5:55 AM
-
Sunday, October 14, 2012 4:59 PM
I don't like such warnings in our code, because each colleague reading it will wonder again if there may be a problem.
Is there a way to make my intention clear so the warning goes away?
-
Monday, October 15, 2012 7:49 PMOwner
A few ways...
You can assign the result to a variable, which will suppress the warning, e.g.
var ignored = t.ContinueWith(...);
You can use pragmas to disable the warning, e.g.
#pragma warning disable 4014
t.ContinueWith(...);
#pragma warning restore 4014or you can suppress the warning at the project level in your project's configuration.
- Proposed As Answer by Stephen Toub - MSFTMicrosoft Employee, Owner Monday, October 15, 2012 7:51 PM

