IOException: The process cannot access the file 'file path' because it is being used by another process

前端 未结 10 2233
陌清茗
陌清茗 2020-11-22 00:13

I have some code and when it executes, it throws a IOException, saying that

The process cannot access the file \'filename\' because it

10条回答
  •  深忆病人
    2020-11-22 00:35

    I had the following scenario that was causing the same error:

    • Upload files to the server
    • Then get rid of the old files after they have been uploaded

    Most files were small in size, however, a few were large, and so attempting to delete those resulted in the cannot access file error.

    It was not easy to find, however, the solution was as simple as Waiting "for the task to complete execution":

    using (var wc = new WebClient())
    {
       var tskResult = wc.UploadFileTaskAsync(_address, _fileName);
       tskResult.Wait(); 
    }
    

提交回复
热议问题