public override void CanClose(Action <bool> callback) { if (!HasChanges) { CheckAndCloseView(); callback(true); return; } var saveResult = dialogService.ShowConfirmationWithCancel("MarkPad", "Save file", "Do you want to save the changes to '" + MarkpadDocument.Title + "'?", new ButtonExtras(ButtonType.Yes, "Save", string.IsNullOrEmpty(MarkpadDocument.SaveLocation) ? "The file has not been saved yet" : "The file will be saved to " + Path.GetFullPath(MarkpadDocument.SaveLocation)), new ButtonExtras(ButtonType.No, "Discard", "Discard the changes to this file"), new ButtonExtras(ButtonType.Cancel, "Cancel", "Cancel closing the application") ); if (saveResult == true) { var finishedWork = shell.DoingWork(string.Format("Saving {0}", MarkpadDocument.Title)); Save() .ContinueWith(t => { finishedWork.Dispose(); if (t.IsCompleted) { CheckAndCloseView(); callback(true); } else { callback(false); } }, TaskScheduler.FromCurrentSynchronizationContext()); return; } if (saveResult == false) { CheckAndCloseView(); callback(true); return; } callback(false); }