Exemplo n.º 1
0
        protected override void OnClosed(EventArgs e)
        {
            _callWndProcHook?.Stop();
            SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_NULL, 0, 0);
            _getMsgHook?.Stop();
            SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_NULL, 0, 0);
            _shellHook?.Stop();
            SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_NULL, 0, 0);
            _cbtHook?.Stop();
            SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_NULL, 0, 0);

            if (_windows != null)
            {
                foreach (Window window in _windows)
                {
                    window.Dispose();
                }
            }

            WindowUtils.ForceAllMessageLoopsToWakeUp();

#if WIN32
            _systemTrayMenu?.Dispose();
            _hotKeyHook?.Dispose();

            if (Environment.Is64BitOperatingSystem && _64BitProcess != null && !_64BitProcess.HasExited)
            {
                foreach (var handle in _64BitProcess.GetWindowHandles())
                {
                    PostMessage(handle, WM_CLOSE, 0, 0);
                }

                if (!_64BitProcess.WaitForExit(5000))
                {
                    _64BitProcess.Kill();
                }

                try
                {
                    File.Delete(_64BitProcess.StartInfo.FileName);
                }
                catch
                {
                }
            }
#endif
            base.OnClosed(e);
            SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_NULL, 0, 0);
        }
Exemplo n.º 2
0
        protected override void OnClosed(EventArgs e)
        {
            _getMsgHook?.Stop();
            _shellHook?.Stop();
            _cbtHook?.Stop();

            if (_windows != null)
            {
                foreach (Window window in _windows)
                {
                    window.Dispose();
                }
            }

            Window.ForceAllMessageLoopsToWakeUp();

#if WIN32
            if (_systemTrayMenu != null)
            {
                _systemTrayMenu.Icon.Visible = false;
            }

            _hotKeyHook?.Dispose();

            if (Environment.Is64BitOperatingSystem && _64BitProcess != null && !_64BitProcess.HasExited)
            {
                foreach (var handle in _64BitProcess.GetWindowHandles())
                {
                    NativeMethods.PostMessage(handle, NativeConstants.WM_CLOSE, 0, 0);
                }

                if (!_64BitProcess.WaitForExit(5000))
                {
                    _64BitProcess.Kill();
                }

                try
                {
                    File.Delete(_64BitProcess.StartInfo.FileName);
                }
                catch
                {
                }
            }
#endif
            base.OnClosed(e);
        }