Possible Duplicate:
Wait until file is unlocked in .NET
I have an open file, like a .Doc or .txt, and I have to wait until the user close it. I already try this, according to Wait until file is unlocked in .NET :
while (true) { try { using (FileStream Fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 100)) { //the file is close break; } } catch (IOException) { //wait and retry Thread.Sleep(1000); } }
This works well ,but it may be possible to find a solution without a try/catch and handler the exception ?
Unfortunately no, there is no other way.
The API doesn't have an event that will fire when a file in unlocked or anything else that is convenient.
Retrying with waits is the best solution with the current API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With