“the process cannot access the file because it is being used by another process” when trying to delete file

前端 未结 4 1238

when deleting files one by one error is generated as \"the process cannot access the file \' because it is being used by another process when trying to delete file\"

cod

4条回答
  •  天命终不由人
    2021-01-21 19:11

    You don't say specifically what file you're trying to delete, but from your question it sounds like you're trying to delete the image file that you loaded. If that's the case, then you have a problem. The documentation for Image.FromFile says:

    The file remains locked until the Image is disposed.

    If you need the ability to delete the file, you'll want to copy the image after you've loaded it, and use that image in your PictureBox. Then you can dispose the loaded image, thereby unlocking the file.

提交回复
热议问题