如何保持ReadDirectoryChangesW从丢失的文件更改 [英] How to keep ReadDirectoryChangesW from missing file changes

查看:444
本文介绍了如何保持ReadDirectoryChangesW从丢失的文件更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关于ReadDirectoryChangesW API函数丢失的文件在互联网上很多帖子时,有很多文件的活动。大多数怪在该ReadDirectoryChangesW函数循环被称为速度。这是一个不正确的假设。我见过的最好的解释是,在下面的帖子,在周一,2008年4月14号下午二时15分27秒

There are many posts on the internet about the ReadDirectoryChangesW API function missing files when there is a lot of file activity. Most blame the speed at which the ReadDirectoryChangesW function loop is called. This is an incorrect assumption. The best explanation I have seen is in the following post, the comment on Monday, April 14, 2008 2:15:27 PM

<一个href="http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/4465cafb-f4ed-434f-89d8-c85ced6ffaa8/">http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/4465cafb-f4ed-434f-89d8-c85ced6ffaa8/

摘要是该ReadDirectoryChangesW函数报告文件的变化,因为他们离开文件后写队列,而不是因为它们是补充。如果太多之前被提交加入,你失去对其中一些通知。你可以看到这与您的实现,如果你只写一个程序来生成目录中的一个1000 +的文件真正快。只要算你有多少文件事件得到通知,你会看到有些时候,您将不会收到所有这些时间。

The summary is that the ReadDirectoryChangesW function reports file changes as they leave the file-write-behind queue, not as they are added. And if too many are added before being committed, you lose notice on some of them. You can see this with your implementation, if you just write a program to generate a 1000+ files in a directory real quick. Just count how many file event notices you get and you will see there are times when you will not receive all of them.

现在的问题是,有没有人发现使用ReadDirectoryChangesW功能,而无需每次都刷新体积可靠的方法?如果用户不是管理员这是不允许的,也可能需要一些时间来完成。

The question is, has anyone found a reliable method to use the ReadDirectoryChangesW function without having to flush the volume each time? This is not allowed if the user is not an Administrator and can also take some time to complete.

推荐答案

我们从来没有见过ReadDirectoryChangesW是100%可靠。但是,处理它的最好办法是分开的,从处理,报告。

We've never seen ReadDirectoryChangesW to be 100% reliable. But, the best way to handle it is separate the "reporting" from the "handling".

我的实现具有螺纹它只有一个工作,重新排队的所有事件。然后第二个线程来处理我的中间队列。你基本上,想要阻止事件尽可能少的报告。

My implementation has a thread which has only one job, to re-queue all events. Then a second thread to process my intermediate queue. You basically, want to impede the reporting of events as little as possible.

在CPU高的情况下,也可以阻碍观察者事件的报告。

Under high CPU situations, you can also impede the reporting of watcher events.

这篇关于如何保持ReadDirectoryChangesW从丢失的文件更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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