![]() Note how the events are declared and that the EnableRaisingEvents property of the file system watcher object is set to true to enable raising events when a change on the path being monitored occurs. Private static void MonitorDirectory(string path)įileSystemWatcher fileSystemWatcher = new FileSystemWatcher() įileSystemWatcher.Created += FileSystemWatcher_Created įileSystemWatcher.Renamed += FileSystemWatcher_Renamed įileSystemWatcher.Deleted += FileSystemWatcher_Deleted įileSystemWatcher.EnableRaisingEvents = true The directory path is passed as an argument to the method. This method would be used to monitor a particular directory and raise events whenever a change occurs. ![]() The following code snippet shows how the MonitorDirectory method would look like. You can build a Windows Service that uses the FileSystemWatcher class and sends out notifications as and when changes occur to the path being watched. Note that a better way to use the FileSystemWatcher class would be by using a Windows Service. Let's create a new console application project in Visual Studio to demonstrate how a typical file system watcher works.
0 Comments
Leave a Reply. |