By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

file system watcher question

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
> 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

P: n/a
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.