我正在尝试使用FileSystemWatcher
类监视目录中的新文件。Filesystemwatcher不会触发事件
我的问题是该事件不会被触发。我的守望类是:
public class Filewatcher
{
private FileSystemWatcher watcher;
public Filewatcher(string path, string filefilter)
{
this.watcher = new FileSystemWatcher();
this.watcher.Path = path;
this.watcher.NotifyFilter = NotifyFilters.FileName; //| NotifyFilters.LastWrite | NotifyFilters.LastAccess
this.watcher.Filter = filefilter;
this.watcher.Created += new FileSystemEventHandler(OnChanged);
}
public void start_watching()
{
//this.watcher.IncludeSubdirectories = true;
this.watcher.EnableRaisingEvents = true;
Console.WriteLine("Press Enter to quit\r\n");
Console.ReadLine();
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
//FileInfo objFileInfo = new FileInfo(e.FullPath);
//if (!objFileInfo.Exists) return;
Console.WriteLine("got the change\r\n");
global_functions.perform_action(Global_Vars.thereader.read(e.FullPath), Global_Vars.thepattern);
}
}
操作系统是Win 7的64位教授
'filefilter'变量的内容是什么!您是否在过滤特定文件..try'*。*'以便为任何类型的文件启用事件 – Anirudha 2012-07-28 17:06:43
filefilter var是“* .eml” path var is c :\文件夹 – user1559904 2012-07-28 17:14:05
我在我的xml-config文件中有一个错字,一切正常。对不起,打开该线程 – user1559904 2012-07-28 17:32:24