C#/WPF 过度使用 FileSystemWatcher?
C#/WPF Overusing FileSystemWatcher?
我正在创建一个简单的应用程序,用户可以在其中录制和播放电视节目四季和剧集 基于用户计算机上已有的文件夹系统。
我想监控实际的 files/folders 是否有任何变化,所以我想在每个季节存储一个 FileSystemWatcher
的实例,以监听相应文件夹中可能发生的任何变化。根据 Seasons 每个 Shows 的数量,最多可以同时收听 1000 个事件。有什么我应该注意的 performance/instability 问题吗?
其中一个答案 here suggests that cranking up the number of listeners up to the 10,000s is definitely a problem, but since I'm not expecting that many records I might go with this answer here 说事件对性能的影响一般来说并没有那么大。有多少听众应该在同一时间 处于活动状态 有某种经验法则吗?非常感谢任何建议。
OP
so I want to store an instance of FileSystemWatcher in every season to listen for any changes that might occur in the corresponding folder
你可以做到这一点,但是当你只有一个时为什么要有多个:
You can watch for changes in files and subdirectories of the specified directory - MSDN
例如
myMonitor.IncludeSubdirectories = true;
OP
Are there are any performance/instability issues I should be aware?
可能,但如果您只使用一个,它会在不降低功能的情况下降低可能性。
无论如何,问题不在于听众数量(好吧,但另一个页面进入了那个),而是 FSW 可以不保证在高容量磁盘activity:
期间不会错过事件
MSDN:
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. Tell me more
我正在创建一个简单的应用程序,用户可以在其中录制和播放电视节目四季和剧集 基于用户计算机上已有的文件夹系统。
我想监控实际的 files/folders 是否有任何变化,所以我想在每个季节存储一个 FileSystemWatcher
的实例,以监听相应文件夹中可能发生的任何变化。根据 Seasons 每个 Shows 的数量,最多可以同时收听 1000 个事件。有什么我应该注意的 performance/instability 问题吗?
其中一个答案 here suggests that cranking up the number of listeners up to the 10,000s is definitely a problem, but since I'm not expecting that many records I might go with this answer here 说事件对性能的影响一般来说并没有那么大。有多少听众应该在同一时间 处于活动状态 有某种经验法则吗?非常感谢任何建议。
OP
so I want to store an instance of FileSystemWatcher in every season to listen for any changes that might occur in the corresponding folder
你可以做到这一点,但是当你只有一个时为什么要有多个:
You can watch for changes in files and subdirectories of the specified directory - MSDN
例如
myMonitor.IncludeSubdirectories = true;
OP
Are there are any performance/instability issues I should be aware?
可能,但如果您只使用一个,它会在不降低功能的情况下降低可能性。
无论如何,问题不在于听众数量(好吧,但另一个页面进入了那个),而是 FSW 可以不保证在高容量磁盘activity:
期间不会错过事件MSDN:
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. Tell me more