gpt4 book ai didi

c# - FileSystemWatcher 无法正常工作

转载 作者:太空狗 更新时间:2023-10-29 22:24:02 24 4
gpt4 key购买 nike

我正在使用 FileSystemWatcher 扫描从 Web 应用程序上传文件的文件夹。我有超过 1000 个文件上传到该文件夹​​。现在,问题是 FileSystemWatcher 在复制第一个文件时启动,有时,它不适用于所有文件。任何建议将不胜感激。

最佳答案

FileSystemWatcher documentation说(强调我的):

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.

.

Note that a FileSystemWatcher may miss an event when the buffer size is exceeded. To avoid missing events, follow these guidelines:

Increase the buffer size by setting the InternalBufferSize property.

Avoid watching files with long file names, because a long file name contributes to filling up the buffer. Consider renaming these files using shorter names.

Keep your event handling code as short as possible.

如果您已经尝试了以上方法,但仍然不够可靠,恐怕唯一的解决办法就是订阅Error。事件并在它发生时手动枚举目录内容。

关于c# - FileSystemWatcher 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7357962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com