My base ViewModel, implemented a couple of years ago, provides this extension method for completing tasks, while preserving the user interface *:
protected void Work(Action job) { IsBusy = true; var stackTrace = new StackTrace(); var task = Task.Factory.StartNew(job) .ContinueWith(failedTask => HandleException(failedTask, stackTrace), TaskContinuationOptions.OnlyOnFaulted) .ContinueWith(_ => { IsBusy = false; }); } void HandleException(Task task, StackTrace stackTrace) { Dispatcher.BeginInvoke( () => { throw new Exception(task.Exception.InnerException.ToString() + stackTrace); }); }
IsBusy is a property observed from the user interface to display a progress bar.
The idea of HandleExceptions is that they are observed and then thrown into the user interface stream, captured by the try/catch in the Main() method and registered before displaying a friendly message to the user and safely closing the application. The strace stack is passed so that the log includes information about the caller.
However, I recently started getting application crash reports without logging and friendly messages with this Windows dialog:

Looking at the Windows event log, we got this EventData:
Application: xxxxApplication.Loader.exe
Framework Version: v4.0.30319
Description: The process was aborted due to an unhandled exception.
Exception Information: System.AggregateException
Stack: in System.Threading.Tasks.TaskExceptionHolder.Finalize ()
Am I doing something wrong with ContinueWith() ?
Is it possible that exceptions for tasks remain unobservable?
<sub> *: I know about BackgroundWorker . Probably at that time it seemed like a better idea or had additional benefits. Sub>