1 回答
TA贡献2003条经验 获得超2个赞
我正在维护一个与您的要求具有相似功能的项目。
在该功能中,我们使用FileSystemWatcher来监控特定 UNC 位置的各种操作。您可以实施OnError将在 UNC 路径不可用时触发的事件。
您可以查看上面的链接了解详细信息,这里仍然是一个简短的示例
using (FileSystemWatcher watcher = new FileSystemWatcher(@"\\your unc path"))
{
// Watch for changes in LastAccess and LastWrite times, and
// the renaming of files or directories.
watcher.NotifyFilter = NotifyFilters.LastAccess
| NotifyFilters.LastWrite
| NotifyFilters.FileName
| NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";
watcher.Created += (s, e) => { Console.WriteLine($"Created {e.Name}"); };
watcher.Deleted += (s, e) => { Console.WriteLine($"Deleted {e.Name}"); };
watcher.Error += (s, e) => { Console.WriteLine($"Error {e.GetException()}"); };
// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console.WriteLine("Press 'q' to quit the sample.");
while (Console.Read() != 'q') ;
}
- 1 回答
- 0 关注
- 119 浏览
添加回答
举报