Reputation: 23
I have multiple processes that running at the same time of my C# program and all of this processes have the same name with different ID and I want to kill specific process of my program by their specific ID or rename them and kill it by their specific name.
Upvotes: 0
Views: 499
Reputation: 334
If you have the id you can do it like this (where id
is an int32
):
Process process = Process.GetProcessById(id);
process.Kill();
Or if you are using LinQ you can do it like this:
Process.GetProcesses()
.Where(x => x.Id.Equals(id))
.FirstOrDefault()
.Kill();
Upvotes: 0
Reputation: 1229
Edit:
Pay attention to Notes and Remarks sections of the documentation, specially for the Kill
method.
Upvotes: 3