FileSystemWatcher Changed event is raised twice
Posted
by user214707
on Stack Overflow
See other posts from Stack Overflow
or by user214707
Published on 2009-11-19T16:55:08Z
Indexed on
2010/05/06
11:58 UTC
Read the original article
Hit count: 849
filesystemwatcher
|c#
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.
© Stack Overflow or respective owner