我需要定期停止并启动filesystemwatcher [英] I need to stop and start the filesystemwatcher at regular intervals

查看:83
本文介绍了我需要定期停止并启动filesystemwatcher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#,,,,我需要定期启动和停止filesystemwatcher任何人请建议我如何停止和启动。例如,如果客户选择5分钟,则需要停止并每隔5分钟启动一次。除了它需要在不同的线程上运行。

I am totally new to C#,,,, I need to start and stop the filesystemwatcher at regular intervals any one please suggest me a way how to stop and start. For example if customer selects 5 min it need's to stop and start every 5min's. As well as it need's to run on a different thread.

推荐答案

如果您正在通过网络工作到具有大量活动的目录,则filewatcher会导致大量网络流量。我一直在研究一个轮询的filewatcher,它在一个计时器滴答内运行,允许你确定检查间隔。我维护指定目录中的文件和时间戳列表。在下一个刻度线上,我将新列表与之前的列表进行比较。如果新列表中缺少某个文件,则删除该文件,如果新列表中的文件不在旧列表中,则添加该文件,如果文件时间戳不同,则文件已更改。对于我的应用程序,我发现15分钟的间隔就足够了。
If you are working across a network to a directory with lot's of activity filewatcher can cause heavy network traffic. I've been working on a polled filewatcher that is run from within a timer tick, allowing you to determine the check interval. I maintain a list of files and timestamps in the specified directory. On the next tick I compare the new list to the previous. If a file is missing from the new list it was deleted, if there is a file in the new list that was not in the old list it was added, and if the file timestamp is different the file was changed. For my application I find that a 15 minute interval is sufficient.


这篇关于我需要定期停止并启动filesystemwatcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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