我怎样才能使它在网络中工作?它可以工作,然后无缘无故停止工作(可能是因为网络不完美)。
Mister Dev
问问题
3508 次
1 回答
7
您需要重新连接 FileSystemWatcher。
将 FileSystemWatcher 类型的变量设置为类的全局变量,添加事件 WatcherError。
在方法内部,添加类似的内容:
private static void WatcherError(object source, ErrorEventArgs e)
{
watcher = new FileSystemWatcher();//You might want to do a method and to setup all config...
while (!watcher.EnableRaisingEvents)
{
try
{
watcher = new FileSystemWatcher();//You might want to do a method and to setup all config...
}
catch
{
System.Threading.Thread.Sleep(30000); //Wait for retry 30 sec.
}
}
}
您不想使用 watcher = new... 您希望有一个方法来添加所有事件并设置路径,但上面的代码让您很好地了解该做什么。
于 2008-11-11T17:32:24.230 回答