What you could to do is contain the monitor with in a while loop that will
exit when processed once.
Inside this loop have a try catch statement that catches the exception that
is thrown when a locked file is accessed. At this point you could then wait
for a certain amount of time, then try to access the file again, and if this
files, wait again etc... until you have access to the file.
so it may look something like this in the creation event handler:
int secondsToSleep = 5;
bool fileAccessed = false;
while ( !fileAccessed )
{
try
{
//
// try to read the file contents here
//
// successful read
fileAccessed = true;
}
catch ( UnauthorizedAccessException ex ) // is this the exception
thrown?
{
// could not access the file
System.Threading.Thread.Sleep ( secondsToSleep * 1000 );
}
}
"ToddT" <tu********@maritzSPAM.com> wrote in message
news:s3********************************@4ax.com...
i've got one app that writes large files to a specific directory that
is watched by another app via an instance of the file system watcher
class. my problem is that the second app is notified when files are
created, but the first app hasn't finished writing to it - causing a
"file is already open" error when the second app trys to open the file
for processing. what i need is a "file closed" event to be thrown by
the file system watcher object. any idea how i can get around this
problem? thx.