469,898 Members | 1,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

FileSystemWatcher: problems with event-catching

Hi,

we have some problems with the following situation:
A remote application A writes files to a directory monitored by a
FileSystemWatcher-instance in application B. A creates the file
with the initial ending "COPY_IN_PROGRESS" and only after
successful copying the file gets renamed to its final ending
"TO_DO". The FileSystemWatcher of B is set to react on the
rename-event and upon recognizing an event some processing
is triggered.
Now the problem is that obviously the event is raised and also
recognized, however the renamed file seems to not yet exist
within the filesystem: the given RenamedEventArgs contain the
new filename, however a File.Exists on this filename, executed
first within the OnEvent-method, returns with false.
Though, if some trace messages are inserted before the File.Exists
everything is working fine, so it seems that there might be some
sort of timing problem. Is it possible that the rename event is
raised before completion of the file system update.
Does anyone know something about this problem or has a solution
ready? (inserting some delay wouldn't be a proper solution; a
completely event-driven solution is preferred)

Thanks in advance
Andreas

Nov 15 '05 #1
1 4367
The Rename and create events of the filesystemwatcher both are quite
eager -- that is, you get the events early, and may not be able to yet
access the file in question.

For any application / service I have written using the FSW, I've normally
done the following
1) Upon getting the event, spawn a "processing thread" and start it up
2) in the processing thread, try to access the file repeatedly until
sucessful (sleeping a bit in-between tries)
3) Let the processing thread completely process the file, the notify the
application thread that the contents are ready.

"Andreas" <Am*******@gmx.net> wrote in message
news:1075727236.354573@nbgm66x...
Hi,

we have some problems with the following situation:
A remote application A writes files to a directory monitored by a
FileSystemWatcher-instance in application B. A creates the file
with the initial ending "COPY_IN_PROGRESS" and only after
successful copying the file gets renamed to its final ending
"TO_DO". The FileSystemWatcher of B is set to react on the
rename-event and upon recognizing an event some processing
is triggered.
Now the problem is that obviously the event is raised and also
recognized, however the renamed file seems to not yet exist
within the filesystem: the given RenamedEventArgs contain the
new filename, however a File.Exists on this filename, executed
first within the OnEvent-method, returns with false.
Though, if some trace messages are inserted before the File.Exists
everything is working fine, so it seems that there might be some
sort of timing problem. Is it possible that the rename event is
raised before completion of the file system update.
Does anyone know something about this problem or has a solution
ready? (inserting some delay wouldn't be a proper solution; a
completely event-driven solution is preferred)

Thanks in advance
Andreas

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Josh Usovsky | last post: by
reply views Thread by Lloyd Sheen | last post: by
1 post views Thread by Troy Murphy | last post: by
3 posts views Thread by Craig Thompson | last post: by
1 post views Thread by John Lee | last post: by
3 posts views Thread by Stampede | last post: by
2 posts views Thread by kmcnet | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.