I have to follow changes of one of folder.
class FileWatcher
{
FileSystemWatcher watcher = new FileSystemWatcher();
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public void StartWatching()
{
watcher.Path = AppDomain.CurrentDomain.BaseDirectory + "\\Read test data";
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("Changes in folder: 'Read test data' ");
}
}
And initialization:
private FileWatcher watch = new FileWatcher();
private void StartReadCVSChanges_Click(object sender, EventArgs e)
{
watch.StartWatching();
}
For some reason when I do have some changes the event handler is called 3 times:
I prefer it to be once.
Any ideas?
see this link Text from there.