Wait for file to be freed by process

后端 未结 11 973
挽巷
挽巷 2020-12-02 14:23

How do I wait for the file to be free so that ss.Save() can overwrite it with a new one? If I run this twice close together(ish), I get a generic GDI+

11条回答
  •  醉梦人生
    2020-12-02 15:11

    bool isLocked = true;
    while (isLocked)
     try {
      System.IO.File.Move(filename, filename2);
      isLocked = false;
     }
     catch { }
     System.IO.File.Move(filename2, filename);
    

提交回复
热议问题