/// <summary> /// Clean up the resources used by the form. /// </summary> /// <param name="disposing">True to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected virtual void Cleanup(bool disposing) { this.Cursor = Cursors.WaitCursor; try { // Provided that the form isn't minimized, update the WindowState setting. if (this.WindowState != FormWindowState.Minimized) { Settings.Default.WindowState = this.WindowState; Settings.Default.Save(); } // If the WindowState property is normal, update the: Location and Size settings. if (this.WindowState == FormWindowState.Normal) { Settings.Default.FormLocation = this.Location; Settings.Default.FormSize = this.Size; Settings.Default.Save(); } CloseChildForms(); DebugMode.Close(); WinHlp32.Close(this.Handle.ToInt32()); // Ensure that the communication port is closed. if (m_CommunicationInterface != null) { CommunicationInterface.CloseCommunication(CommunicationInterface.CommunicationSetting.Protocol); } if (disposing) { // Method called by consumer code. Call the Dispose method of any managed data members that implement the dispose method. // Cleanup managed objects by calling their Dispose() methods. if (components != null) { components.Dispose(); } if (m_DataDictionary != null) { m_DataDictionary.Dispose(); } if (m_ControlPanel != null) { m_ControlPanel.Dispose(); } if (m_TimerWibuBox != null) { m_TimerWibuBox.Stop(); m_TimerWibuBox.Enabled = false; m_TimerWibuBox.Tick -= new EventHandler(WibuBoxCheck); m_TimerWibuBox.Dispose(); } } // Whether called by consumer code or the garbage collector free all unmanaged resources and set the value of managed data // members to null. m_DataDictionary = null; m_TimerWibuBox = null; m_ControlPanel = null; m_CommunicationInterface = null; m_MenuInterfaceApplication = null; m_MenuInterfaceEvent = null; m_MenuInterfaceSelfTest = null; m_MenuInterfaceWatch = null; m_MenuInterfaceWibuKey = null; m_Security = null; } catch (Exception) { // Don't do anything, just ensure that an exception is not thrown. } this.Cursor = Cursors.Default; }
/// <summary> /// <para>Initialize the PTU application:</para> /// <para>(1) position the form;</para> /// <para>(2) update the LogStatus StatusLabel, regardless of whether this is visible for the current project;</para> /// <para>(3) set the font;</para> /// <para>(4) instantiate the menu interfaces to the various sub-systems;</para> /// <para>(5) create the required PTU configuration sub-directories if they don't already exist;</para> /// <para>(6) initialize the menu system;</para> /// <para>(7) set the 'Checked' property of the 'Configure/Enumeration' menu option; and</para> /// <para>(8) clear the Restart property to ensure that the program terminates when the Close() method is called.</para> /// </summary> private void InitializePTU() { // Display the form using the saved settings. this.WindowState = Settings.Default.WindowState; this.Location = Settings.Default.FormLocation; this.Size = Settings.Default.FormSize; // Update the LogStatus StatusStrip even though it may be invisible on some projects. LogStatus = EventLogSavedStatus.NotApplicable; // Update the Font. Parameter.Font = FormOptions.GetOSFont(false); Font = Parameter.Font; // Menu interfaces. m_MenuInterfaceApplication = new MenuInterfaceApplication(this); m_MenuInterfaceWatch = new MenuInterfaceWatch(this); m_MenuInterfaceEvent = new Event.MenuInterfaceEvent(this); m_MenuInterfaceSelfTest = new SelfTest.MenuInterfaceSelfTest(this); // Create the PTU configuration sub-directories. DirectoryManager.CreateConfigurationSubDirectories(); // Get the collection of function keys associated with the form. This allows any child form that is called indirectly to restore the function // keys on exit. m_ToolStripItemCollectionMainWindow = General.GetToolStripItemCollection(m_ToolStripFunctionKeys); m_MenuItemConfigureEnumeration.Checked = m_Enumeration; // Ensure that the application terminates when the Close() method is called. If this flag is asserted, the application automatically restarts when the // Close() method exits. m_Restart = false; }