468,110 Members | 1,841 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

file system watcher question

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.
Nov 21 '05 #1
2 878
> 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.


Another thing you can do is have your application that generates the file
generate it a temporary location, and then File.Move() it to the "drop zone"
that the other application is listening on.

--
Peace & happy computing,

Mike Labosh, MCSD

"Mr. McKittrick, after very careful consideration, I have
come to the conclusion that this new system SUCKS!"
~~ General Barringer ~~
"ToddT" <tu********@maritzSPAM.com> wrote in message
news:9c********************************@4ax.com...
Nov 21 '05 #2
Jim
"ToddT" <tu********@maritzSPAM.com> wrote in message
news:9c********************************@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.


I have got around this kind of issue in the past with various ruses, none of
them entirely satisfactory, but they may help. I am assuming that the second
app is yours...

1. Don't open the file if its length is zero (if the first app writes all
its data in one go this may be the case, depending on the windows version)
2. Build some delay in to the second app so that it doesn't try and open the
file within n seconds or minutes of the LastWriteTime of the file, available
via the FileInfo object. You will need to make the delay n configurable so
you can tune the second app to correspond to the size of file being
received.

Good luck!

--Jim.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ron Vecchi | last post: by
7 posts views Thread by Allen Anderson | last post: by
reply views Thread by Jack David | last post: by
2 posts views Thread by Jack David | last post: by
5 posts views Thread by ToddT | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.