private async Task <bool> HandleSimulatorRetryAsync(Simulator sim, Exception ex)
        {
            // Show a TaskDialog.
            bool result = false;

            await this.Dispatcher.InvokeAsync(new Action(() =>
            {
                if (!this.closeWindowAfterStop)
                {
                    var dialog = new TaskDialog()
                    {
                        Title = AppName,
                        MainInstruction = "Simulator interrupted!",
                        Content = ex.Message,
                        ExpandedInformation = GetExceptionDetailsText(ex),
                        MainIcon = TaskDialog.TaskDialogIcon.Warning,
                        CommonButtons = TaskDialog.TaskDialogButtons.Cancel
                    };
                    dialog.Flags |= TaskDialog.TaskDialogFlags.UseCommandLinks |
                                    TaskDialog.TaskDialogFlags.ExpandFooterArea;

                    var buttonTryAgain = dialog.CreateCustomButton("Try again\n" +
                                                                   "The Simulator will try to run the current action again.");
                    var buttonStop = dialog.CreateCustomButton("Stop the Simulator");

                    dialog.CustomButtons = new TaskDialog.ICustomButton[] { buttonTryAgain, buttonStop };
                    dialog.DefaultCustomButton = buttonStop;

                    dialog.Show(this);

                    if (dialog.ResultCustomButton == buttonTryAgain)
                    {
                        result = true;
                    }
                }
            }));

            return(result);
        }