Hi,
I have a Windows Service written in C# whos purpose is to sniff a folder to look for changes in the folder. If a file is created or changed, it should get its name and start an object the sends the file to another server.
The problem I have is that when for example a txt file gets edited and saved with notepad, OnChanged gets executed twice (the test file was a tiny txt file).
I connected to the process with the VS.Net debugger and verified that the problem actually is that the OnChanged event is launched twice.
I launch my FileSystem watcher object like this :
protected void startLogging()
{
System.IO.FileSystemWatcher myWatcher = new System.IO.FileSystemWatcher();
myWatcher.Path = @"C:\temp\FileLog";
myWatcher.IncludeSubdirectories = true;
myWatcher.WaitForChanged(WatcherChangeTypes.All,30 00);
myWatcher.Filter = "*.txt";
myWatcher.Created +=new System.IO.FileSystemEventHandler(myWatcher_Created );
myWatcher.Changed +=new System.IO.FileSystemEventHandler(myWatcher_Changed );
myWatcher.EnableRaisingEvents = true;
}
startLogging() is being launched on very last line of the main class constructor.
Anyone had the same problem as I do? Obviously, I would like OnChanged to be called only after the file is finished changing (Closehandle()??).
Thanks in advance,
Erik Herje
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>kyUjMLQ6MEm77TU4aR2LqQ==</Id>