如何杀死一个C#程序? [英] How to kill a C# process?

查看:104
本文介绍了如何杀死一个C#程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个C#程序,解压文件和工作在这个文件

I am building a C# program that unzips a file, and work on this file.

有时候,我得到这个消息:该进程无法访问文件c: ....因为它正被另一个进程使用

Sometimes I get this message: "the process cannot access the file c:.... because it is being used by another process"

我能做些什么?怎么杀呢?

What I can do? How to kill it?

推荐答案

您必须找出哪些程序正在访问该文件。难道你忘记了退出的自己的应用程序,或者是否有任何其他访问文件?

You have to find out which program that is accessing the file. Have you forgotten to exit one of your own applications, or are there any other accessing the file?

您可以编写C#代码杀死一个过程,而是一种更好的办法。要找出为什么它已经被另一个进程

You can write C# code to kill a process, but a better approach would be to find out why it is already being used by another process.

要杀死名的 nameOfProcess 的在C#中的所有进程:

To kill all processes with name nameOfProcess in C#:

Process[] ps = Process.GetProcessesByName("nameOfProcess");

foreach (Process p in ps)
    p.Kill();



此外,作为@Darin笔记,你可以在这个其他线程SO看看:的 http://stackoverflow.com/questions/317071 /怎么办,我找到的出 - 这 - 过程 - 被锁定,一个文件-C

这是由提到的的Sysinternals工具。 @Darin在评论在 http://technet.microsoft.com/en被发现-us / Sysinternals的/ bb896645.aspx

The sysinternals tools that is mentioned by @Darin in the comments is found at http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

这篇关于如何杀死一个C#程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆