Reputation: 11624
I am running an external process in a custom msbuild task. This task is in assembly A which is called when I'm building project B. Everything works fine. However, when trying to clean the project. Visual Studio 2008 gives me an error saying "the process cannot access assembly A because it is being used by another process". Restarting Visual Studio fixes this problem.
The code calling the external process is as follows
Process process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = @"c:\program.exe",
Arguments = "",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
process.Start();
process.WaitForExit(5000);
How do I troubleshoot a problem like that?
Update: Using Process Explorer, it tells me devenv.exe has a handle on assembly A. Why and how do I stop it from having a handle on it?
Upvotes: 1
Views: 205
Reputation: 27236
That is sort of normal… devenv.exe is executing the process but the handles are still there. I'm not sure how can you avoid that, but I'm sure that after a few minutes the handle may go away.
I'm not sure if Garbage Collection has anything to do with it, but have you tried something like this?:
using (Process process = new Process()){
process.StartInfo = new ProcessStartInfo { FileName = @"c:\program.exe", Arguments = "", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true };
process.Start();
process.WaitForExit(5000);
}
That will at least set the scope of the object.
Upvotes: 0
Reputation: 901
I am not entirely sure of the goal of your question. You can use process explorer to find out which process is locking the file.
Something like here : http://windowsxp.mvps.org/processlock.htm
Upvotes: 1