How to terminate a process in c#

By name

foreach (Process p in Process.GetProcessesByName("process_name"))
{
	try
	{
		p.Kill();
		p.WaitForExit();
	}
	catch { }
}

By id

try
{
	Process p = Process.GetProcessById(process_id);
	p.Kill();
	p.WaitForExit();
}
catch { }
Categories: C# Tags: , , , ,
%d bloggers like this: