C# .NET - fileSystemWatcher problem

Asked By Nidhal Gaza on 06-May-09 05:24 AM
Hi all,
I worte a Csharp application which monitors a shared folder on a network using fileSystemWatcher component, the problem is that if the network connection is lost for few seconds fileSystemWatcher stops monitoring without raising any errors.  Also, it doesn't start monitoring when the connection is re-established.
I noticed the same thing happens if you are monitoring files in a local folder and you delete it, fileSystemWatcher won't error, and won't restart monitoring if you put the folder back.

How can I force fileSystemWatcher to detect the problem and start monitoring as soon as the network connection is re-established?

Thanks in advance
Ravenet Rasaiyah replied to Nidhal Gaza on 06-May-09 05:35 AM

Yes,

 To this task, i mean to monitor the connection dropping  you can't do with FileSystemwatcher to this you need use anther API to do this.

look here how you can do this

http://stackoverflow.com/questions/627068/how-does-filesystemwatcher-work-on-another-computers-directory

thank you
Santhosh N replied to Nidhal Gaza on 06-May-09 05:37 AM

You need to create events for when folder is deleted and other events to watch that...

check here for more info...

http://www.codeguru.com/vb/gen/vb_system/directoriesandfiles/article.php/c4827


http://www.devguru.com/features/tutorials/watchfolderact/watchfolder.asp

Jeff replied to Nidhal Gaza on 12-May-10 12:42 PM
The Error event of the FileSystemWatcher object is raised when the folder is no longer available.  My suggestion would be to catch this event and then re-initiate the routine (after a slight delay perhaps) of watching the folder