FileSystemWatcher OnChanged

D

D2

Hi,

I'm using FileSystemWatcher to monitor certain folders in file system.
In some specific scenarios where a large file is copied to the
monitored folder, I receive too many Onchanged events. I'm clueless as
how can i detect the file has finally been copied? any help would be
appreciated.

thanks,
d2
 
P

Peter Ritchie [C# MVP]

You can't know for sure. You can't even know if the two OnChanged events
were the result of the same action or the same application.

The best you can do is timeout after a certain amount of time without
receiving OnChanged. e.g. when you get an OnChanged for a file, set a timer
for 500 ms. If you get another OnChanged event, reset that timer. When the
Elapsed event for the timer is raised, you know nothing has changed the file
in 500ms and whatever action that was being performed might be completed.
 

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