Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error "unable to copy file because it is being used by another process

I use windowsform application using C# language, I have many forms, and when I want to traverse from one to another, I use this.Hide();

When I use this method, I receive the shown error,

I know that the solution is to end process using windows task manager, But the question is that Is there any way I can use travel between forms without leading to this error?

 Error  9   Unable to copy file "obj\x86\Debug\WindowsFormsApplication1.exe" to "bin\Debug\WindowsFormsApplication1.exe". The process cannot access the file 'bin\Debug\WindowsFormsApplication1.exe' because it is being used by another process.  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets  2868
like image 770
Hossein Hadavi Avatar asked Aug 19 '13 19:08

Hossein Hadavi


People also ask

How do you fix because it is being used by another process?

Process cannot access file because it is being used by another process error message. To resolve this error: Press Ctrl + Alt + Delete, then click Task Manager. Ensure you're on the Processes tab.

How do I copy a file using another process?

Copy it threw an exception "File is being used by another process" again. But by simply copying this file in windows (ctrl+c) and pasting (ctrl+v) it worked.


1 Answers

Although you Hide() your forms, they still remain as a part of the process. If you don't close every form properly, the process will remain running and you cannot recompile your project and eventually you will have to kill your process using the taskmanager.
Visual Studio tries to rewrite your executable and if the executable runs as a process, Windows will refuse to write to your .exe.

like image 128
bash.d Avatar answered Oct 08 '22 00:10

bash.d