我在 FileSystemWatcher 类上进行了扩展,以合并一个 FolderCount 监视器和 FolderEmpty 监视器,如果文件夹达到指定数量的文件或文件夹返回到空状态,它们会引发事件。我似乎可以正常工作,并且在发生这些情况时会引发事件。
但是,我的问题是,当我的 FileSystemWatcher 首次初始化时,它会自动进入检查指定文件夹的文件夹内容以获取文件计数。如果已经达到限制,我需要立即引发事件,而不是等待 FileSystemWatcher 报告它。
目前我似乎只能通过插入.Created
and.Deleted
调用来引发事件,但是,因为没有文件被创建或删除,我不知道如何手动引发我的事件。
Public Sub Initialize()
SetFolderCountStatus() 'Set the isFolderEmpty flag based on file contents
If Not isFolderEmpty Then
If options.WatchForFolderCount Then
If FileCountReached(options.FileCountToWatch) Then
RaiseEvent EventFolderCount(sender, e) 'Sender and e are never defined
End If
End If
End If
End Sub
我的问题是两者sender
都e
没有填充任何东西,因为它们位于我的WatcherEventArgs
.
我确信这可以做得更好,但我不确定。任何帮助,将不胜感激。谢谢