windows FileSystemWatcher 停止监视网络文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7818545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:17:53  来源:igfitidea点击:

FileSystemWatcher stops monitoring network folder

windowsnetworkingc#-4.0filesystemwatcher

提问by Tomas

I have developed file queue system, where several Apps from different Windows machines watch the same mapped network drive for file changes and proceed files. To watch mapped drive for changes I use FileSystemWatcher (c# .NET 4.0) and everything works fine for ~one day after that FileSystemWatcher stops monitoring. I have tried to play with FileSystemWatcher.Errorevent to catch exceptions if any. Unfortunately Error event is not always fired. I do not find a way to solve the problem, FileSystemWatcher stops working and no error are throw. Any suggestion?

我开发了文件队列系统,其中来自不同 Windows 机器的几个应用程序监视相同的映射网络驱动器以进行文件更改并处理文件。要查看映射驱动器的更改,我使用 FileSystemWatcher (c# .NET 4.0) 并且在 FileSystemWatcher 停止监视后的一天内一切正常。我尝试使用FileSystemWatcher.Error事件来捕获异常(如果有)。不幸的是,错误事件并不总是被触发。我没有找到解决问题的方法,FileSystemWatcher 停止工作并且没有抛出错误。有什么建议吗?

回答by Yahia

FileSystemWatcheris NOT reliable for network drives... for example it is known to have some problems with SAMBA shares...

FileSystemWatcher对网络驱动器不可靠……例如,众所周知,SAMBA 共享存在一些问题……

Another point is if you are using it in a Windows Service... trying to access a network drive from a Windows Service usually leads to some problem (depending on Windows version etc.).

另一点是,如果您在 Windows 服务中使用它...尝试从 Windows 服务访问网络驱动器通常会导致一些问题(取决于 Windows 版本等)。

回答by Jonas Rembratt

Networks gets disconnected. It's natural.

网络断开连接。这是自然的。

Have a look here: http://www.codeguru.com/csharp/.net/net_general/eventsanddelegates/article.php/c9113

看看这里:http: //www.codeguru.com/csharp/.net/net_general/eventsanddelegates/article.php/c9113

Good luck

祝你好运