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

前端 未结 10 2198
陌清茗
陌清茗 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:28

    My below code solve this issue, but i suggest First of all you need to understand what causing this issue and try the solution which you can find by changing code

    I can give another way to solve this issue but better solution is to check your coding structure and try to analyse what makes this happen,if you do not find any solution then you can go with this code below

    try{
    Start:
    ///Put your file access code here
    
    
    }catch (Exception ex)
     {
    //by anyway you need to handle this error with below code
       if (ex.Message.StartsWith("The process cannot access the file"))
        {
             //Wait for 5 seconds to free that file and then start execution again
             Thread.Sleep(5000);
             goto Start;
        }
     }
    

提交回复
热议问题