C # solution when the program prompts "this process is being used by another process, so this process cannot access this file"
This article mainly introduces the solution that the C # program prompts "the process is being used by another process, so the process cannot access the file". This article solves this problem by rewriting the program code, for more information, see
Problem description:
After the image is loaded, it is displayed. When you delete the image, the message "……" is displayed. It is being used by another process, so the process cannot access the file ......."
Solution:
Original code:
The Code is as follows:
Iml. Images. Add (Image. FromFile (potopath + "\" + fi. Name ));
Changed:
The Code is as follows:
Image img = Image. FromFile (potopath + "\" + fi. Name );
Iml. Images. Add (img );
Img. Dispose ();
Where: ImageList iml = new ImageList ();
It is also feasible to modify other types of files by reference.