I have problem with FileSystemWatcher class. I Have this code:
RunningPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Reporter\\";
XMLConfigWatcher = new FileSystemWatcher(RunningPath);
XMLConfigWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size;
XMLConfigWatcher.Filter = "database.xml";
XMLConfigWatcher.Changed += new FileSystemEventHandler(XMLConfigChanged);
XMLConfigWatcher.EnableRaisingEvents = true;
I want to observe one file - database.xml file. It it small file. I have win XP and it doesn't running on my computer, but my friend has Win 7 and it fires property. What's the reason and how to correct it?
And, of course, I attach Changed Event:
public void XMLConfigChanged(object sender, FileSystemEventArgs e)
{
MessageBox.Show("Config changed from outside.");
foreach (ProgramToGrid f in collection)
{
f.watcher.finalize();
}
App.Current.Dispatcher.Invoke((Action)delegate
{
collection.Clear();
});
XmlAccess xml = XmlAccess.getInstance();
foreach (Program f in xml.getApps())
{
ProgramToGrid ptg = new ProgramToGrid(f.getFolder(), f.getMail(), f.getSubject());
ptg.watcher = new BugWatcher(f.getFolder(), f.getMail(), f.getSubject());
App.Current.Dispatcher.Invoke((Action)delegate
{
collection.Add(ptg);
});
}
}