Beispiel #1
0
        /// <summary>
        /// Shutdown / cleanup
        /// </summary>
        public void Exit()
        {
            LOG.Info("Exit: " + EnvironmentInfo.EnvironmentToString(false));

            // Close all open forms (except this), use a separate List to make sure we don't get a "InvalidOperationException: Collection was modified"
            List <Form> formsToClose = new List <Form>();

            foreach (Form form in Application.OpenForms)
            {
                if (form.Handle != this.Handle && !form.GetType().Equals(typeof(Greenshot.ImageEditorForm)))
                {
                    formsToClose.Add(form);
                }
            }
            foreach (Form form in formsToClose)
            {
                try
                {
                    LOG.InfoFormat("Closing form: {0}", form.Name);
                    this.Invoke((MethodInvoker) delegate { form.Close(); });
                }
                catch (Exception e)
                {
                    LOG.Error("Error closing form!", e);
                }
            }

            // Now the sound isn't needed anymore
            try
            {
                SoundHelper.Deinitialize();
            }
            catch (Exception e)
            {
                LOG.Error("Error deinitializing sound!", e);
            }

            // Inform all registed plugins
            try
            {
                PluginHelper.instance.Shutdown();
            }
            catch (Exception e)
            {
                LOG.Error("Error shutting down plugins!", e);
            }

            // Gracefull shutdown
            try
            {
                Application.DoEvents();
                Application.Exit();
            }
            catch (Exception e)
            {
                LOG.Error("Error closing application!", e);
            }

            ImageOutput.RemoveTmpFiles();

            // Store any open configuration changes
            try
            {
                IniConfig.Save();
            }
            catch (Exception e)
            {
                LOG.Error("Error storing configuration!", e);
            }

            // Remove the application mutex
            FreeMutex();
        }
Beispiel #2
0
        /// <summary>
        /// Shutdown / cleanup
        /// </summary>
        public void exit()
        {
            ClipboardHelper.DeregisterClipboardViewer(this.Handle);

            LOG.Info("Exit: " + EnvironmentInfo.EnvironmentToString(false));

            // Close all open forms (except this), use a separate List to make sure we don't get a "InvalidOperationException: Collection was modified"
            List <Form> formsToClose = new List <Form>();

            foreach (Form form in Application.OpenForms)
            {
                if (form.Handle != this.Handle && !form.GetType().Equals(typeof(Greenshot.ImageEditorForm)))
                {
                    formsToClose.Add(form);
                }
            }
            foreach (Form form in formsToClose)
            {
                try
                {
                    LOG.InfoFormat("Closing form: {0}", form.Name);
                    this.Invoke((MethodInvoker) delegate { form.Close(); });
                }
                catch (Exception e)
                {
                    LOG.Error("Error closing form!", e);
                }
            }

            // Make sure hotkeys are disabled
            try
            {
                HotkeyControl.UnregisterHotkeys();
            }
            catch (Exception e)
            {
                LOG.Error("Error unregistering hotkeys!", e);
            }

            // Now the sound isn't needed anymore
            try
            {
                SoundHelper.Deinitialize();
            }
            catch (Exception e)
            {
                LOG.Error("Error deinitializing sound!", e);
            }

            // Inform all registed plugins
            try
            {
                PluginHelper.instance.Shutdown();
            }
            catch (Exception e)
            {
                LOG.Error("Error shutting down plugins!", e);
            }

            // Gracefull shutdown
            try
            {
                Application.DoEvents();
                Application.Exit();
            }
            catch (Exception e)
            {
                LOG.Error("Error closing application!", e);
            }

            // Store any open configuration changes
            try
            {
                IniConfig.Save();
            }
            catch (Exception e)
            {
                LOG.Error("Error storing configuration!", e);
            }

            // Remove the application mutex
            FreeMutex();

            // make the icon invisible otherwise it stays even after exit!!
            if (notifyIcon != null)
            {
                notifyIcon.Visible = false;
                notifyIcon.Dispose();
                notifyIcon = null;
            }
        }