我想使用filesystemwatcher來監視多個文件夾,如下所示。我下面的代碼,只是看一個文件夾:文件系統監視器 - 多個文件夾
public static void Run()
{
string[] args = System.Environment.GetCommandLineArgs();
if (args.Length < 2)
{
Console.WriteLine("Usage: Watcher.exe PATH [...] [PATH]");
return;
}
List<string> list = new List<string>();
for (int i = 1; i < args.Length; i++)
{
list.Add(args[i]);
}
foreach (string my_path in list)
{
WatchFile(my_path);
}
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
private static void WatchFile(string watch_folder)
{
watcher.Path = watch_folder;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.xml";
watcher.Changed += new FileSystemEventHandler(convert);
watcher.EnableRaisingEvents = true;
}
但上面的代碼監視一個文件夾,在文件夾等沒有影響。這是什麼原因?
無論是下面的答案的是正確的。所以指向他們兩個 – user726720 2013-03-26 12:14:40