Link to home
Start Free TrialLog in
Avatar of mustang_larry
mustang_larry

asked on

.Net FileSystemWatcher Class copying large files- events.

c# .NET file system watcher class.

Using the file system class seems like a nice way to detect
when files appear in a folder.

When copying a large file the created event is fired right away.

What would be the best way to detect that file has been completely copied
before consuming the file for use.

here is a good example of the class.
http://www.codeguru.com/csharp/csharp/cs_network/article.php/c6043/

ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Learned
What is the file size when the create event is fired?

Bob
Avatar of grant300
grant300

When doing FTP, the common practice is to rename the file (with FTPrename) after the transfer is complete.  Your consuming application looks for files with one extension while the transfer is done with a different extension, or, alternatively, you can rename the file between folders.

You may have to modify your file-producing application to rename the file after it is done creating it.

Regards,
Bill
Try this:  

System.Threading.Thread.Sleep(<some value>)

before starting any operation on the file.
another sollution:
I had similar problem, here is how I solved it..Chose time (in miliseconds, to delay action after watched event is fired)
Set code below  under FileSystemWatcher1_Created, just before you want to do copying..

Me.FileSystemWatcher1.WaitForChanged(IO.WatcherChangeTypes.Created, 60000)