kill child C#
/// <summary>
/// Kill a process, and all of its children, grandchildren, etc.
/// </summary>
/// <param name="pid">Process ID.</param>
private static void KillProcessAndChildren(int pid)
{
// Cannot close 'system idle process'.
if (pid == 0)
{
return;
}
ManagementObjectSearcher searcher = new ManagementObjectSearcher
("Select * From Win32_Process Where ParentProcessID=" + pid);
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
}
try
{
Process proc = Process.GetProcessById(pid);
proc.Kill();
}
catch (ArgumentException)
{
// Process already exited.
}
}
Also in C#:
- c# pass mouse events to parent
- c# max sequence contains no elements
- unity move character
- how to load the active scene unity
- c# MessageBox
- flip boolean c#
- kill child C#
- compose graphql query string in c#
- see if two string arrays are equal c#
- generics in c#
- c# return multiple value unity
- unity c# set gameobject active
- c# only letters
- how to parse a string to an integer c#
- how to join array indexes with comma in c#
- while loop in c#
- unity movement on forward
- unity onclick object
- unity make a int arry with preset values
- devexpress objectspace to session
- c# get executable path
- covert char[] to string C#
- null coalesce ternary c#
- unity rigidbody constraints