public FileWatcher(string directory, string filter)
{
_dispatcher = Dispatcher.CurrentDispatcher;
_watcher = new FileSystemWatcher();
_watcher.BeginInit();
_watcher.Path = directory;
_watcher.Filter = filter;
_watcher.IncludeSubdirectories = false;
_watcher.InternalBufferSize = InitialBufferSize;
_watcher.NotifyFilter
= NotifyFilters.DirectoryName
| NotifyFilters.FileName
| NotifyFilters.LastWrite
| NotifyFilters.Attributes
| NotifyFilters.Security
| NotifyFilters.Size;
// note: all events are on threadpool threads!
_watcher.Created += onCreated;
_watcher.Deleted += onDeleted;
_watcher.Changed += onChanged;
_watcher.Renamed += onRenamed;
_watcher.Error += onError;
_watcher.EndInit();
_watcher.EnableRaisingEvents = true;
}