Watcher.Changed += new FileSystemEventHandler(watcher_Changed) Watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime Watcher.Path = Path.GetDirectoryName(path) Private FileSystemWatcher watcher = new FileSystemWatcher() I made a simple class that works fine for me. (One for the size, one for the last write timestamp, one for the last access timestamp, and one more for.something else.) Try setting the FileSystemWatcher's NotifyFilter property to a single type of change and see if you continue to get multiple events. You might be getting more than one event from different changes. #Vb.net filewatcher software#_lastTimeFileWatcherEventRaised = DateTime.Now Īssuming the path is the same every time, is it possible the program you are using to save the file is actually doing the save in pieces? Or do you have more than one Blah instantiated?ĭo you have any antivirus auto-protect software running? Those might be touching the file in the process.Įdit: Or maybe there's something to do with how windows is saving the file. If( (_lastTimeFileWatcherEventRaised).TotalMilliseconds < 500 ) If the last time that the event has been raised is only a few msec away, Therefore, this workaround is necessary: There are a lot of resources about this to be found on the Internet, events of the FileSystemWatcher to be called twice. There is a nasty bug in the FileSystemWatch which causes the This is how I've worked around it: if( e.ChangeType = WatcherChangeTypes.Changed ) If anyone knows a fix that is more elegant plz let me know. If it has been raised less then xxx msec ago, I return from my eventhandler. I've solved it by keeping track of the last time the eventhandler has been raised. So, perhaps it is a flaw in the FileSystemWatcher. This is because Notepad updates the Archived attribute for the file during this operation.Ī while ago, I've experience the same problem.Īfter some searching thtrough the web, it appeared that I was not the only one having this issue. For example, if you use the ChangeEventFilter to specify that you want to watch only for attribute changes, and then you write to a file in the directory you are watching using Notepad, you will raise an event. Note: Notepad may also cause other interesting event generations. Because FileSystemWatcher monitors the operating system activities, all events that these applications fire will be picked up. Other applications may perform in the same manner. Notepad writes to the disk in batches that create the content of the file and then the file attributes. This is because Notepad performs multiple file system actions during the writing process. For example, if you use a FileSystemWatcher component to monitor the creation of new files in a directory, and then test it by using Notepad to create a file, you may see two Created events generated even though only a single file was created. You may notice in certain situations that a single creation event generates multiple Created events that are handled by your component. Multiple Created Events Generated for a Single Action From the "Troubleshooting FileSystemWatcher Components" section of the VS.NET documentation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |