/// <summary> /// Stop all execution. /// </summary> public void StopAllExecution() { Notify(this, new StopAllExecution()); TimerMessageForm theTimerMessageForm = new TimerMessageForm(); theTimerMessageForm.ShowDialogSpecifiedTime("Stopping execution...", 3000); }
/// <summary> /// This method will be called is this project form is closed or when /// the main form is closed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ProjectForm2_Closing(object sender, System.ComponentModel.CancelEventArgs e) { bool theMainFormIsClosing = true; // We don't know if calling of this method this is a consequence of closing this project form or // as a consequence of closing the main form. // The following code is needed to find this out (see the Form class Closing event in MSDN) if (((MainForm)ParentForm)._IsClosing) { // Closing is done through the Exit menu item. theMainFormIsClosing = true; } else { // The position of the cursor in screen coordinates. Point theCursorPosition = Cursor.Position; if ((ParentForm.Top + SystemInformation.CaptionHeight) < theCursorPosition.Y) { theMainFormIsClosing = false; } else { theMainFormIsClosing = true; } } // Close if allowed. if (theMainFormIsClosing) { // Don't do anything. // The Main form will also receive a closing event and handle the closing of the application. } else { e.Cancel = false; MainForm theMainForm = (MainForm)ParentForm; DialogResult theDialogResult; if (IsExecuting()) { // Ask the user if execution needs to be stopped. theDialogResult = MessageBox.Show("Executing is still going on.\nStop execution?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (theDialogResult == DialogResult.Yes) { // Stop the execution. Notify(new StopExecution(this)); // Because execution is performed in a different thread, wait some // time to enable the execution to stop. Also give feedback to the user // of this waiting by showing a form stating this. TimerMessageForm theTimerMessageForm = new TimerMessageForm(); theTimerMessageForm.ShowDialogSpecifiedTime("Stopping execution...", 3000); // Find out if execution really has stopped. if (IsExecuting()) { theDialogResult = MessageBox.Show("Failed to stop execution.\n This form will not be closed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; } } else { e.Cancel = true; } } if (ParentForm.MdiChildren.Length == 1) { // This is the last project form that is being closed, // so the project needs to be closed. if (!e.Cancel) { // e.Cancel is false, so no execution takes place any more. // Close the project. // If unsaved changes exist, give the user the possibility to save them. if (projectApp.AreProjectOrSessionsChanged()) { _MainForm.Save(true); } if (projectApp.HasUserCancelledLastOperation()) { // The user has cancelled the close operation. // Cancel the closing of this last project form. e.Cancel = true; } else { // The user has not cancelled the close operation. projectApp.Close(true); projectApp = null; Notify(new ProjectClosed()); } } } } }