Waiting for busy file to become available

M

marc.gibian

I am writing a simple C# application to read some files in an FTP drop
directory. Occasionally the program will attempt to open a file that is
in the process of being written. FileStream will throw an exception if
the file is busy while its constructor is attempting to open it. I
would prefer to simply make some form of call that will test if the
file is locked/busy, and if so wait until it is unlocked or a maximum
time period has elapsed. All of the solutions I've found thus far use a
poll loop, retrying the FileStream constructor, or File.Open method. I
would really prefer not to use this solution, but can't find a more
direct solution.
 
D

Dr. Net

Hi Marc,
You should check out the msdn regarding the FileSystemWatcher class.
Getting an event when the file's properties change, might give you a
better strategy.

Uri.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top