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 ?