如何检查Filesystemwatcher是否已断开连接 [英] How to check Filesystemwatcher is disconnected

查看:77
本文介绍了如何检查Filesystemwatcher是否已断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何查找filesystemwatcher是否断开连接.如果断开连接,我想重新启动filesystemwatcher,请提供解决方案.

Hi,
How to find the filesystemwatcher is disconnected or not. if disconnected i want to reboot the filesystemwatcher please give solution.

推荐答案

我个人已经编写了自己的文件系统监视程序,该文件监视程序继承了FileSystemWatcher.我需要监视启动应用程序时并不总是连接的外部USB驱动器.因此,首先,如果未连接驱动器,则EnableRaisingEvents将会失败,我有一个自定义例程,该例程检查目标文件夹的存在,当目标文件夹存在时,它将触发EnableRaisingEvents.如果/当驱动器断开连接时,FileSystemWatcher引发Error事件,该事件触发我的例程再次开始监视该文件夹的存在.我还有一个内置的例程,该例程监视FileSystemWatcher中的最后一个事件,如果自上次事件以来已超过X分钟,则它将禁用引发事件,然后尝试重新启用引发事件.几年来,它已经在大量使用中取得了成功.

因此,长话短说,检查EnableRaisingEvents属性(true ==正常,false ==无效),并将处理程序添加到Error事件,这将在转储大量文件且缓冲区溢出或驱动器断开连接时触发. .
I personally have written my own file system watcher that inherits FileSystemWatcher. I had the need to monitor external USB drives that were not always connected when my application was started. So first off if the drive is not connected then EnableRaisingEvents will fail, I have a custom routine that checks for the destination folders existance and when it exists will then trigger EnableRaisingEvents. If/when the drive gets disconnected the FileSystemWatcher raises the Error event which triggers my routine to start monitoring for that folders existence again. I also have a builtin routine that monitors the last event from the FileSystemWatcher and if it has been longer than X minutes since the last event then it will disable raising events and then try and re-enable raising events. It has been successful in heavy use for several years now.

So, long story shorter check the EnableRaisingEvents property (true == working, false == not working) and add a handler to the Error event, this will be triggered when mass files get dumped and there is a buffer overrun, or drive disconnected etc.


这篇关于如何检查Filesystemwatcher是否已断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆