Emulate waiting on File.Open in C# when file is locked

前端 未结 2 1701
感情败类
感情败类 2020-12-19 08:37

I have, essentially, the same problem as this poster, but in C#: Waiting until a file is available for reading with Win32

More information: we have code that calls <

相关标签:
2条回答
  • 2020-12-19 08:57

    You can call Marshal.GetHRForException() within the catch clause to get the error code. No need for reflection:

    using System.Runtime.InteropServices;
    
    if (Marshal.GetHRForException(e) == ERROR_SHARING_VIOLATION)
        ....
    
    0 讨论(0)
  • 2020-12-19 09:10

    Your best bet is using reflection unfortunately. Of course, since you sleep for 1sec between attempts, the performance costs will most likely go unnoticed.

    0 讨论(0)
提交回复
热议问题