How to handle unexpected errors in a Dataflow

Answered How to handle unexpected errors in a Dataflow

  • Sunday, October 14, 2012 11:36 AM
     
      Has Code


    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 Function

    The 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
     
     Answered
    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?



    • Edited by pmeinl Sunday, October 14, 2012 5:02 PM
    • Edited by pmeinl Monday, October 15, 2012 5:49 AM clarified
    •  
  • Monday, October 15, 2012 7:49 PM
    Owner
     
     Proposed Answer

    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 4014

    or you can suppress the warning at the project level in your project's configuration.