public static Task ContinueWithExceptionHandling(this Task task, Window window, Action <bool> action) { if (task == null) { throw new ArgumentNullException("task"); } if (window == null) { throw new ArgumentNullException("window"); } if (action == null) { throw new ArgumentNullException("action"); } return(task.ContinueWith(t => { if (task.IsFaulted) { Exception ex; if (task.Exception != null) { task.Exception.LogError(); ex = task.Exception.InnerException; } else { ex = new InvalidOperationException(LocalizedStrings.Str2914); ex.LogError(); } new MessageBoxBuilder() .Caption(LocalizedStrings.Str2915) .Text(ex.ToString()) .Error() .Owner(window) .Show(); } action(!task.IsFaulted); }, TaskScheduler.FromCurrentSynchronizationContext())); }