예제 #1
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();
            }
        }
예제 #2
0
        public void Run()
        {
            if (!this.running)
            {
                this.running = true;

                InitializeComponent();

                // SUPER IMPORTANT - since we are using the contextMenu as the synchronizing object, its .Handle must be created first
                // this will force creation of the handle without showing the menu
                Utility.WriteDebugInfo("ContextMenu Handle: {0}", this.contextMenu.Handle);

                // scaling factor
                float currentDPI = 0;
                using (Graphics g = this.contextMenu.CreateGraphics())
                {
                    currentDPI = g.DpiX;
                }
                ApplicationMain.ScalingFactor = currentDPI / 96;

                // configure the controller
                this.controller = Controller.GetController();
                this.controller.FailedToStart          += new EventHandler <PortConflictEventArgs>(controller_FailedToStart);
                this.controller.FailedToStartUDPLegacy += new EventHandler <PortConflictEventArgs>(controller_FailedToStartUDPLegacy);
                this.controller.Initialize(Application.ExecutablePath, this.contextMenu);

                this.wpr = new WndProcReader(WndProc);

                StartGrowl();

                OnProgramRunning(this, EventArgs.Empty);

                HandleSystemNotifications();

                // signal the ProgramLoadedResetEvent so anybody that was waiting on it can start their work
                ProgramLoadedResetEvent.Set();

                // Normally we shouldnt ever explicitly call GC.Collect(), but since many of the prefs
                // are read from files on disk, they usually end up on the Large Object Heap. LOH objects
                // only get collected in Gen2 collections, so we want to do this here before the app
                // really gets going to clean up our initialization process.
                Utility.WriteDebugInfo("Program loaded. Force GC to clean up LOH");
                ApplicationMain.ForceGC();

                // auto updater
                this.updater = new Updater(Application.StartupPath);
                this.updater.CheckForUpdateComplete += new CheckForUpdateCompleteEventHandler(updater_CheckForUpdateComplete);
                this.autoUpdateTimer.Interval        = 20 * 1000;
                this.autoUpdateTimer.Tick           += new EventHandler(autoUpdateTimer_Tick);
                this.autoUpdateTimer.Start();

                // while it may seem strange to call the Detector to see if we are installed, it is the best way
                // to ensure that plugins/displays see the same values that we do
                Growl.CoreLibrary.Detector detector = new Growl.CoreLibrary.Detector();
                if (!detector.IsInstalled)
                {
                    // something is not right with the registry setting, so lets fix it now
                    Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(Growl.CoreLibrary.Detector.REGISTRY_KEY, true);
                    if (key == null)
                    {
                        key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(Growl.CoreLibrary.Detector.REGISTRY_KEY);
                    }
                    using (key)
                    {
                        key.SetValue(null, Application.ExecutablePath);
                    }
                }
            }
        }