FileSystemWatcher does not work properly. It only responds when the first change occurs. If I then change a second file, nothing happens.
public class ImageViewModel : INotifyPropertyChanged
{
public static ImageViewModel singletonInstance { get; set; }
FileSystemWatcher watcher;
private readonly BackgroundWorker worker1;
public ImageViewModel()
{
...
watcher = new FileSystemWatcher(RootPath);
watcher.EnableRaisingEvents = true;
watcher.IncludeSubdirectories = true;
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
this.worker1 = new BackgroundWorker();
this.worker1.DoWork += this.DoWork1;
this.worker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker1_Completed);
}
...
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
editedFile = e.FullPath;
if (worker.IsBusy == true || worker1.IsBusy == true)
{
autoEvent.WaitOne();
}
else
{
this.worker1.RunWorkerAsync();
}
}
}
Can you help me solve this problem?