Thursday, October 21, 2004 11:23 PM
FileSystemWatcher event is triggered twice (solution)
I've seen this behavior during a demo of mine today using notepad and a filesystemwatcher that monitors a single file. According to the Visual Studio .NET documentation (but you have to search a bit to find it): "This behavior is by design". The funny fact is that Notepad is in fact playing the evil role in this scenario. Let me paste this info here:
Multiple Created Events Generated for a Single Action
You may notice in certain situations that a single creation event generates multiple Created events that are handled by your component. 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. This is because Notepad performs multiple file system actions during the writing process. Notepad writes to the disk in batches that create the content of the file and then the file attributes. Other applications may perform in the same manner. Because FileSystemWatcher monitors the operating system activities, all events that these applications fire will be picked up.
Note Notepad may also cause other interesting event generations. 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 . This is because Notepad updates the Archived attribute for the file during this operation.
For more information (if you have VS.NET installed with MSDN): ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbtbsTroubleshootingUNCPathNamesNotAcceptedOnNT4Machines.htmDel.icio.us
| Digg It