Ji Cheng Wang - MSFT
Hi bslim,
The OnChanged event handler of FileSystemWatcher will be raised more than one time when there is a file or a folder changed. This is because the framework is passing through the native OS events, which may be any number of things, depending on the application. The work around way for this issue is to try to monitor the changed folder or file and then notify the framework. Try to check out the following sample codes for reference:
Code Block
static void Main(string[] args)
{
watcher = new FileSystemWatcher();
watcher.Path = mailbox;
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press Enter to quit\r\n");
Console.ReadLine();
}
public static void OnChanged(object source, FileSystemEventArgs e)
{
watcher.EnableRaisingEvents = false;
FileInfo objFileInfo = new FileInfo(e.FullPath);
if (!objFileInfo.Exists) return; // ignore the file open
ProcessAllFiles(e.FullPath);
}
Try to check out this article about "Workaround Double Callback of FileSystemWatcher Event Handler" for details - http://www.codeproject.com/useritems/FileWatcher.asp
Hope this helps,
Regards,
This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.