FileSystemWatcher and multiple changed events

D

D2

Hi,

I have this problem when working with FileSystemWatcher class. I m
using one of these objects to watch over a folder. Whenever i big file
from another folder to the folder being watched, I get created event
and multiple changed events.
After the file is copied (fully) i want to read the file and perform
some operations on it. Now the issue is, there is no way to find that
the file has been copied entirely.

there are some workarounds like try to open file in a loop until u r
successful (this is the time when file got copied). This has a
potential problem, if I copy large number of files, it will skip about
50% of them .. depending on the size of files being copied.

Any better solutions?

Thanks,
D2
 
N

Nicholas Paldino [.NET/C# MVP]

D2,

Is the file being copied part of a controlled environment? In other
words, is the file being copied as the result of an operation from a client
which you have control over, or is it meant as a general file monitoring
system?

There was a system where I needed to process files once they were
dropped in a directory. I wanted to use the file system watcher, but I
couldn't know for sure when the writing of the file was complete. Because
we were in control of the client, we made it so that the client wrote a zero
byte marker file which would tell the FileSystemWatcher when to process the
original file. Since the marker file was zero bytes, one could reasonably
assume that the marker file and original file were both closed by the end of
processing.

Perhaps you could do something similar?
 

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