开发者

Get Files count from FileSystemWatcher Created event?

开发者 https://www.devze.com 2023-04-09 22:12 出处:网络
I\'m wondering if there\'s a way to get the amount of files that are going to be copied? What I mean is following...

I'm wondering if there's a way to get the amount of files that are going to be copied? What I mean is following... I'm writing an app that contains grid, which functions like windows explorer. When I'm drag-droping files, they are copied to a destination folder and my grid is supposed to refresh. My FileSystemWatcher sends me events about created files & grid refreshes, but for multiple files it refreshes multiple times =/ So is there a way to find out how many files were copied, or to get a开发者_StackOverflow中文版 collection of files just in one event?


I would build an adapter that throttles and raises similar events after a delay. This ThrottlingFileSystemWatcher would look virtually identical to a standard FileSystemWatcher but instead of raising an event for every file, it would queue up the files and raise an event some TimeSpan later (say 5 seconds, but make it configurable) and include all the files it saw in its EventArgs.


I would make the refresh less accurat an let it only refresh again after a defined time. So it could solve this problem for all future refresh Problems and or user refreshes. I also would make the refresh time configurable and every user is happy with it.


I once coded a solution similar to @Austin Salonen's.

When a new file event is received, check to see if a count down timer is running.

  • If not, start it
  • If it is running, reset it to 3 seconds (time
    depends on file size and speed of file transfers).

When the count down timer triggers, THEN update the GUI.

0

精彩评论

暂无评论...
验证码 换一张
取 消