Example #1
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    Microsoft.Win32.SystemEvents.TimeChanged -= new EventHandler(SystemEvents_TimeChanged);

                    if (this.components != null)
                    {
                        this.components.Dispose();
                    }

                    if (this.mainForm != null)
                    {
                        if (this.mainForm.OnOffButton != null)
                        {
                            this.mainForm.OnOffButton.Switched -= new Growl.UI.OnOffSwitchedEventHandler(OnOffButton_Switched);
                        }

                        this.mainForm.FormClosed -= new FormClosedEventHandler(mainForm_FormClosed);
                        this.mainForm.Dispose();
                        this.mainForm = null;
                    }

                    if (this.settingsToolStripMenuItem != null)
                    {
                        this.settingsToolStripMenuItem.Click -= new System.EventHandler(this.settingsToolStripMenuItem_Click);
                        this.settingsToolStripMenuItem.Dispose();
                        this.settingsToolStripMenuItem = null;
                    }

                    if (this.pauseGrowlToolStripMenuItem != null)
                    {
                        this.pauseGrowlToolStripMenuItem.Click -= new System.EventHandler(this.pauseGrowlToolStripMenuItem_Click);
                        this.pauseGrowlToolStripMenuItem.Dispose();
                        this.pauseGrowlToolStripMenuItem = null;
                    }

                    if (this.unpauseGrowlToolStripMenuItem != null)
                    {
                        this.unpauseGrowlToolStripMenuItem.Click -= new System.EventHandler(this.unpauseGrowlToolStripMenuItem_Click);
                        this.unpauseGrowlToolStripMenuItem.Dispose();
                        this.unpauseGrowlToolStripMenuItem = null;
                    }

                    if (this.muteToolStripMenuItem != null)
                    {
                        this.muteToolStripMenuItem.Click -= new System.EventHandler(this.muteToolStripMenuItem_Click);
                        this.muteToolStripMenuItem.Dispose();
                        this.muteToolStripMenuItem = null;
                    }

                    if (this.unmuteToolStripMenuItem != null)
                    {
                        this.unmuteToolStripMenuItem.Click -= new System.EventHandler(this.unmuteToolStripMenuItem_Click);
                        this.unmuteToolStripMenuItem.Dispose();
                        this.unmuteToolStripMenuItem = null;
                    }

                    if (this.checkForUpdatesToolStripMenuItem != null)
                    {
                        this.checkForUpdatesToolStripMenuItem.Click -= new System.EventHandler(this.checkForUpdatesToolStripMenuItem_Click);
                        this.checkForUpdatesToolStripMenuItem.Dispose();
                        this.checkForUpdatesToolStripMenuItem = null;
                    }

                    if (this.exitToolStripMenuItem != null)
                    {
                        this.exitToolStripMenuItem.Click -= new System.EventHandler(this.exitToolStripMenuItem_Click);
                        this.exitToolStripMenuItem.Dispose();
                        this.exitToolStripMenuItem = null;
                    }

                    if (this.toolStripSeparator1 != null)
                    {
                        this.toolStripSeparator1.Dispose();
                        this.toolStripSeparator1 = null;
                    }

                    if (this.contextMenu != null)
                    {
                        this.contextMenu.Close();
                        this.contextMenu.Dispose();
                        this.contextMenu = null;
                    }

                    if (this.notifyIcon != null)
                    {
                        this.notifyIcon.DoubleClick -= new System.EventHandler(this.notifyIcon_DoubleClick);
                        this.notifyIcon.Dispose();
                        this.notifyIcon = null;
                    }

                    if (this.updateForm != null)
                    {
                        this.updateForm.Close();
                        this.updateForm.Dispose();
                        this.updateForm = null;
                    }

                    if (this.updater != null)
                    {
                        this.updater.CheckForUpdateComplete -= new CheckForUpdateCompleteEventHandler(updater_CheckForUpdateComplete);
                        this.updater.Dispose();
                        this.updater = null;
                    }

                    if (this.controller != null)
                    {
                        this.controller.FailedToStart -= new EventHandler<PortConflictEventArgs>(controller_FailedToStart);
                        this.controller.FailedToStartUDPLegacy -= new EventHandler<PortConflictEventArgs>(controller_FailedToStartUDPLegacy);
                        this.controller.Dispose();
                        this.controller = null;
                    }

                    if (this.autoUpdateTimer != null)
                    {
                        this.autoUpdateTimer.Tick -= new EventHandler(autoUpdateTimer_Tick);
                        this.autoUpdateTimer.Dispose();
                        this.autoUpdateTimer = null;
                    }

                    UnregisterHotKeys();

                    if (this.wpr != null)
                    {
                        this.wpr.DestroyHandle();
                        this.wpr = null;
                    }
                }
                catch
                {
                    // suppress
                }
            }
            base.Dispose(disposing);
        }
Example #2
0
        private void KillForm(object obj)
        {
            if (mainForm != null)
            {
                this.mainForm.FormClosed -= new FormClosedEventHandler(mainForm_FormClosed);
                this.mainForm.OnOffButton.Switched -= new Growl.UI.OnOffSwitchedEventHandler(OnOffButton_Switched);

                this.mainForm.Dispose();
                this.mainForm = null;

                // Normally we shouldnt ever explicitly call GC.Collect(), but since the form can use a
                // relatively large amount of memory for the UI components, we want to make sure that is
                // all freed when the form is closed.
                Utility.WriteDebugInfo("Form closed. Force GC to clean up LOH");
                ApplicationMain.ForceGC();
            }
        }
Example #3
0
        public void ShowForm()
        {
            if (this.mainForm != null && this.mainForm.Visible)
            {
                // do nothing for now
            }
            else
            {
                this.mainForm = new MainForm();
                this.mainForm.FormClosed += new FormClosedEventHandler(mainForm_FormClosed);
                this.mainForm.InitializePreferences();

                this.mainForm.OnOffButton.On = this.controller.IsOn;
                this.mainForm.OnOffButton.Switched += new Growl.UI.OnOffSwitchedEventHandler(OnOffButton_Switched);

                UpdateState(this.controller.IsOn, !this.controller.IsRunning);
                this.mainForm.DoneInitializing();

                this.mainForm.ShowForm();
            }

            Growl.DisplayStyle.Win32.SetForegroundWindow(this.mainForm.Handle);
        }