I am building a C# program that unzips a file, and work on this file.
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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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?
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.
To kill all processes with name nameOfProcess in C#:
Also, as @Darin notes, you could take a look at this other SO thread: How do I find out which process is locking a file using .NET?
The sysinternals tools that is mentioned by @Darin in the comments is found at http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx