我有FileSystemWatcher类的问题。我有这段代码:
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;
我想观察一个文件 - database.xml文件。它是小文件。我赢得了XP并且它没有在我的计算机上运行,但是我的朋友有Win 7并且它激发了财产。是什么原因以及如何纠正它?
当然,我附上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);
});
}
}