FileSystemWatcher Changed event is raised twice
- by user214707
I have an application where I am looking for a text file and if there are any changes made to the file I am using the onchanged eventhandler to handle the event. I am using the notifyfilters.Lastwritetime but still the event is getting fired twice.Here is the code.
public void Initialize()
{
FileSystemWatcher _fileWatcher = new FileSystemWatcher();
_fileWatcher.Path = "C:\\Folder";
_fileWatcher.NotifyFilter = NotifyFilters.LastWrite;
_fileWatcher.Filter = "Version.txt";
_fileWatcher.Changed += new FileSystemEventHandler(OnChanged);
_fileWatcher.EnableRaisingEvents = true;
}
private void OnChanged(object source, FileSystemEventArgs e)
{
.......
}
I my case the Onchanged is called twice when I change the text file version.txt and save it.Please help.