I had a problem with catching the exception from Task.Run
which was resolved by changing the code as follows. I\'d like to know the difference between handling
Building on @MennoJongerius answer the following keeps asynchronousity and moves the exception from the .wait to the Async Completed event handler:
Public Event AsyncCompleted As AsyncCompletedEventHandler
).ContinueWith(Sub(t)
If t.IsFaulted Then
Dim evt As AsyncCompletedEventHandler = Me.AsyncCompletedEvent
evt?.Invoke(Me, New AsyncCompletedEventArgs(t.Exception, False, Nothing))
End If
End Sub)