英文:
How to kill process by specific Id in c#
问题
我有多个同时运行的进程与我的C#程序,所有这些进程都具有相同的名称,但具有不同的ID,我想通过它们的特定ID来终止我的程序的特定进程,或者重命名它们并按其特定名称终止它们。
英文:
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.
答案1
得分: 3
Edit:
请注意文档的 Notes 和 Remarks 部分,特别是对于 Kill
方法。
英文:
Edit:
Pay attention to Notes and Remarks sections of the documentation, specially for the Kill
method.
答案2
得分: 0
如果您拥有ID,可以像这样执行操作(其中id
是一个int32
):
Process process = Process.GetProcessById(id);
process.Kill();
或者,如果您正在使用LinQ,可以像这样执行操作:
Process.GetProcesses()
.Where(x => x.Id.Equals(id))
.FirstOrDefault()
.Kill();
英文:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论