FileSystemWatcher提高了两次改变.... [英] FileSystemWatcher raises Changed Twice....

查看:74
本文介绍了FileSystemWatcher提高了两次改变....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人注意到FileSystemWatcher在更改文件时会将更改后的事件

引发两次?


您是否知道为什么这是案例?

解决方案

之前曾多次询问过这个问题:
http://groups.google.com/groups?lnk=...mWatcher+两次


" ljh" <再*** @ groups.please>在消息中写道

新闻:cM ***************** @ bignews1.bellsouth.net ...

有没有人还是注意到FileSystemWatcher在更改文件时会两次引发更改的
事件吗?

您是否知道为什么会这样?


我看到了那些......但是那里没有真正的解决方案。


这似乎是另一个.Nets gotcha '的。听起来很棒的东西,

但是在现实世界的编程中并没有真正解决。


对我来说可怕的部分不是多余的改变消息所以就像错失事件的可能性一样。微软的文档说Windows

操作系统通过FileSystemWatcher在你创建的缓冲区中通知你的组件文件更改

。如果在短时间内有很多变化,

缓冲区可能会溢出。这会导致组件无法跟踪目录中的更改,并且只会提供一揽子通知。使用InternalBufferSize属性增加缓冲区的大小是非常昂贵的,因为它的b / b
来自无法换出到磁盘的非分页内存,所以请保持

缓冲区虽小但足够大,不会错过任何文件更改事件。要使
避免缓冲区溢出,请使用NotifyFilter和IncludeSubdirectories

属性,以便过滤掉不需要的更改通知。

http://msdn2.microsoft.com/en-us/lib...er(d = ide).aspx


所以如果您的InternalBufferSize没有设置为足够高,那么您可能会错过更改,因为移动包含许多文件

和/或子目录的目录。我说把它设置得比你需要的高。毕竟,

更昂贵。比没有宣传的应用程序?

" Lebesgue" <乐****** @ gmail.com>在留言中写道

新闻:uY ************* @ TK2MSFTNGP02.phx.gbl ...

这已被多次询问之前:
http: //groups.google.com/groups?lnk=...mWatcher+twice

" ljh" <再*** @ groups.please>在消息中写道
新闻:cM ***************** @ bignews1.bellsouth.net ...

有没有人注意到当文件被更改时,FileSystemWatcher会将更改的
事件提升两次吗?

你知道为什么会这样吗?




有关InternalBufferSize属性的更多信息,请转到
http://msdn2.microsoft.com/en-us/lib...ze(d = ide) .aspx


" ljh" <再*** @ groups.please>在消息中写道

新闻:qv ***************** @ bignews1.bellsouth.net ...

我看到了那些......但是那里没有真正的解决方案。

这似乎是另一个.Nets gotcha'的。听起来不错的东西,但是在现实世界的编程中并没有真正发挥作用。

对我来说可怕的部分不是多余的改变信息,而是可能的
可能性失踪事件微软的文档说Windows操作系统会在FileSystemWatcher创建的缓冲区中通知组件文件更改。如果
短时间内有很多变化,缓冲区可能会溢出。这会导致组件丢失跟踪目录中的更改,并且它只会提供一揽子通知。使用
InternalBufferSize属性增加缓冲区的大小是昂贵的,因为它来自无法转换到磁盘的非分页内存,因此保持缓冲区尽可能小但足够大不要错过任何文件更改事件。为避免缓冲区溢出,请使用NotifyFilter和IncludeSubdirectories属性,以便您可以过滤掉不需要的更改通知。
http://msdn2.microsoft.com/en-us/lib...er(d = ide).aspx

所以变化可能发生,就像移动一样如果您的InternalBufferSize设置得不够高,您可能会错过一个包含许多文件
和/或子目录的目录。我说把它设置得比你需要的高。毕竟,更昂贵的是什么?比没有宣传的应用程序?

" Lebesgue" <乐****** @ gmail.com>在消息中写道
新闻:uY ************* @ TK2MSFTNGP02.phx.gbl ...

以前曾多次询问过这个问题:
http:// groups。 google.com/groups?lnk=...mWatcher+twice

" ljh" <再*** @ groups.please>在消息中写道
新闻:cM ***************** @ bignews1.bellsouth.net ...

有没有人注意到当文件被更改时,FileSystemWatcher会将更改的
事件提升两次吗?

你知道为什么会这样吗?





Has anyone else noticed that the FileSystemWatcher raises the changed event
twice when a file is changed?

Do you have any idea why this is the case?

解决方案

This has been asked several times before:
http://groups.google.com/groups?lnk=...mWatcher+twice

"ljh" <Re***@groups.please> wrote in message
news:cM*****************@bignews1.bellsouth.net...

Has anyone else noticed that the FileSystemWatcher raises the changed
event twice when a file is changed?

Do you have any idea why this is the case?



I saw those.....but there is no real solution listed there.

This seems to be another of .Nets gotcha''s. Something that sounds great,
but doesn''t really work out in real world programming.

The scary part for me is not the redundant changed messages so much as the
possibility of missing events. Microsoft''s documentation says "The Windows
operating system notifies your component of file changes in a buffer created
by the FileSystemWatcher. If there are many changes in a short time, the
buffer can overflow. This causes the component to lose track of changes in
the directory, and it will only provide blanket notification. Increasing the
size of the buffer with the InternalBufferSize property is expensive, as it
comes from non-paged memory that cannot be swapped out to disk, so keep the
buffer as small yet large enough to not miss any file change events. To
avoid a buffer overflow, use the NotifyFilter and IncludeSubdirectories
properties so you can filter out unwanted change notifications. "
(http://msdn2.microsoft.com/en-us/lib...er(d=ide).aspx)

So changes can happen, as with the moving of a directory with many files
and/or subdirectories, that you may miss if your InternalBufferSize is not
set high enough. I say set it higher than you may need. After all, what is
more "expensive" than an app that does not perform as advertised?
"Lebesgue" <le******@gmail.com> wrote in message
news:uY*************@TK2MSFTNGP02.phx.gbl...

This has been asked several times before:
http://groups.google.com/groups?lnk=...mWatcher+twice

"ljh" <Re***@groups.please> wrote in message
news:cM*****************@bignews1.bellsouth.net...

Has anyone else noticed that the FileSystemWatcher raises the changed
event twice when a file is changed?

Do you have any idea why this is the case?




For more info on the InternalBufferSize property go to
http://msdn2.microsoft.com/en-us/lib...ze(d=ide).aspx.

"ljh" <Re***@groups.please> wrote in message
news:qv*****************@bignews1.bellsouth.net...

I saw those.....but there is no real solution listed there.

This seems to be another of .Nets gotcha''s. Something that sounds great,
but doesn''t really work out in real world programming.

The scary part for me is not the redundant changed messages so much as the
possibility of missing events. Microsoft''s documentation says "The
Windows operating system notifies your component of file changes in a
buffer created by the FileSystemWatcher. If there are many changes in a
short time, the buffer can overflow. This causes the component to lose
track of changes in the directory, and it will only provide blanket
notification. Increasing the size of the buffer with the
InternalBufferSize property is expensive, as it comes from non-paged
memory that cannot be swapped out to disk, so keep the buffer as small yet
large enough to not miss any file change events. To avoid a buffer
overflow, use the NotifyFilter and IncludeSubdirectories properties so you
can filter out unwanted change notifications. "
(http://msdn2.microsoft.com/en-us/lib...er(d=ide).aspx)

So changes can happen, as with the moving of a directory with many files
and/or subdirectories, that you may miss if your InternalBufferSize is not
set high enough. I say set it higher than you may need. After all, what
is more "expensive" than an app that does not perform as advertised?
"Lebesgue" <le******@gmail.com> wrote in message
news:uY*************@TK2MSFTNGP02.phx.gbl...

This has been asked several times before:
http://groups.google.com/groups?lnk=...mWatcher+twice

"ljh" <Re***@groups.please> wrote in message
news:cM*****************@bignews1.bellsouth.net...

Has anyone else noticed that the FileSystemWatcher raises the changed
event twice when a file is changed?

Do you have any idea why this is the case?





这篇关于FileSystemWatcher提高了两次改变....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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