예제 #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);
        }