我想使用 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;
}
但是上面的代码监控一个文件夹,对另一个文件夹没有影响。这是什么原因?