Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

FileSystemMonitor - wait til file copies completely

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob - 24 Jan 2008 15:54 GMT
I need to monitor a file system to tell when a certain file (type) has
been copied to a folder. It would seem logical to have some
pre-packaged mechanism to detect completion of the copy, but it
apparently does not exist. (The detector triggers as soon as the file
-starts- to copy, not when it's complete)

I've seen people mention hooking a call to file open into a timer. Is
there no better way to do this? Seems like there should be a much
simpler mechanism available by now.
Nicholas Paldino [.NET/C# MVP] - 24 Jan 2008 16:17 GMT
Bob,

   The only way I have gotten around this is to have whatever process
writing the file write a "marker" file.  A zero byte file to indicate that
the file writing is complete.  Then, when the FileSystemWatcher detects this
file, it determines (from the filename is the system I used) the name of the
file to process, and when it is done, deletes the marker file, or both.

   If you can't change the process that is outputting the file, then a
timer is really the only way you can do this.  Either that, or if you know
that the process writing the file will have exclusive access to the file,
cycle in a loop (waiting in between so you don't spin the processor
needlessly) until you can get access to the file, or you time out (as
specified by you).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I need to monitor a file system to tell when a certain file (type) has
> been copied to a folder. It would seem logical to have some
[quoted text clipped - 5 lines]
> there no better way to do this? Seems like there should be a much
> simpler mechanism available by now.
Oolis Kraprin - 25 Jan 2008 13:19 GMT
Try handling the Watchers Changed rather than Created event. Usually
Created is fired when the write starts, and Changed is fired again
when the write is complete and the file is closed by the writer.

> I need to monitor a file system to tell when a certain file (type) has
> been copied to a folder. It would seem logical to have some
[quoted text clipped - 5 lines]
> there no better way to do this? Seems like there should be a much
> simpler mechanism available by now.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.