FileSystemWatcher 与轮询以监视文件更改 [英] FileSystemWatcher vs polling to watch for file changes

查看:24
本文介绍了FileSystemWatcher 与轮询以监视文件更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置一个应用程序来监视在本地或网络驱动器上的目录中创建的文件.

I need to setup an application that watches for files being created in a directory, both locally or on a network drive.

FileSystemWatcher 或轮询计时器将是最佳选择.我过去使用过这两种方法,但没有广泛使用.

Would the FileSystemWatcher or polling on a timer would be the best option. I have used both methods in the past, but not extensively.

这两种方法有什么问题(性能、可靠性等)?

What issues (performance, reliability etc.) are there with either method?

推荐答案

我看到文件系统观察程序在生产和测试环境中失败.我现在认为它很方便,但我认为它不可靠.我的模式是使用文件系统观察器观察更改,但偶尔轮询以捕获丢失的文件更改.

I have seen the file system watcher fail in production and test environments. I now consider it a convenience, but I do not consider it reliable. My pattern has been to watch for changes with the files system watcher, but poll occasionally to catch missing file changes.

如果您有用户界面,您还可以让您的用户刷新"更改而不是轮询.我会将它与文件系统观察器结合起来.

If you have a UI, you can also give your user the ability to "refresh" for changes instead of polling. I would combine this with a file system watcher.

这篇关于FileSystemWatcher 与轮询以监视文件更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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