BudgetAnalyser.ShellController.ShellClosing C# (CSharp) Method

ShellClosing() public method

Notify the ShellController the Shell is closing.
public ShellClosing ( ) : Task
return Task
        public async Task<bool> ShellClosing()
        {
            if (this.persistenceOperations.HasUnsavedChanges)
            {
                bool? result = this.uiContext.UserPrompts.YesNoBox.Show("There are unsaved changes, save before exiting?", "Budget Analyser");
                if (result != null && result.Value)
                {
                    // Save must be run carefully because the application is exiting.  If run using the task factory with defaults the task will stall, as background tasks are waiting to be marshalled back to main context
                    // which is also waiting here, resulting in a deadlock.  This method will only work by first cancelling the close, awaiting this method and then re-triggering it.
                    await this.persistenceOperations.SaveDatabase();
                }

                return true;
            }

            return false;
        }