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 <
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)
....
Your best bet is using reflection unfortunately. Of course, since you sleep for 1sec between attempts, the performance costs will most likely go unnoticed.