我正在嘗試使用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