In general, the way this is usually done is through the TaskScheduler , and not through Dispatcher.BeginInvoke . Try the following:
task.ContinueWith(t => { MessageBox.Show("Error: " + t.Exception.InnerExceptions[0].Message); }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext());
If you create this task in a user interface thread, the above should work as you expect.
If, however, you run this task in the background thread, you need to provide a clean way to get the correct TaskScheduler to continue. This can be done by capturing the scheduler while building a window or other tools, and then using it later.
source share