/// <summary>
        /// Soft closes from a WinForms or WPF process.
        /// </summary>
        /// <param name="process">The process to close.</param>
        public void SoftKillWinApp(IProcess process)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            if (_api.AttachConsole((uint)process.Id))
            {
                _api.SetConsoleCtrlHandler(null, true);
                try
                {
                    if (!_api.GenerateConsoleCtrlEvent())
                    {
                        return;
                    }

                    process.WaitForExit();
                }
                finally
                {
                    _api.FreeConsole();
                    _api.SetConsoleCtrlHandler(null, false);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Soft closes from a WinForms or WPF process.
 /// </summary>
 /// <param name="process">The process to close.</param>
 public void SoftKillWinApp(IProcess process)
 {
     if (api.AttachConsole((uint)process.Id))
     {
         api.SetConsoleCtrlHandler(null, true);
         try {
             if (!api.GenerateConsoleCtrlEvent())
             {
                 return;
             }
             process.WaitForExit();
         } finally {
             api.FreeConsole();
             api.SetConsoleCtrlHandler(null, false);
         }
     }
 }