- Clarified Dispose logic for ConPTY Terminal and Process - Disposing a ConPTY Process now kills it and its children - ConPTY Terminal now cleans up everything in its Dispose - Wired up missing Dispose calls in various finalizers - Removed CTRL_CLOSE_EVENT handling. This event never seems to actually happen. Fixes https://github.com/jumptrading/FluentTerminal/issues/94
35 lines
932 B
C#
35 lines
932 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Management;
|
|
|
|
using FluentTerminal.App.Services;
|
|
|
|
namespace FluentTerminal.SystemTray
|
|
{
|
|
public static class ProcessUtils
|
|
{
|
|
/// <summary>
|
|
/// Kill a process, and all of its children, grandchildren, etc.
|
|
/// </summary>
|
|
/// <param name="pid">Process ID.</param>
|
|
public static void KillTree(int pid)
|
|
{
|
|
var searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
|
|
foreach (ManagementObject mo in searcher.Get())
|
|
{
|
|
KillTree(Convert.ToInt32(mo["ProcessID"]));
|
|
}
|
|
|
|
try
|
|
{
|
|
Process.GetProcessById(pid).Kill();
|
|
}
|
|
catch (ArgumentException)
|
|
{
|
|
// Process already exited.
|
|
}
|
|
}
|
|
}
|
|
}
|