JustMeGaaRa
JustMeGaaRa

Reputation: 520

Get Files count from FileSystemWatcher Created event?

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 collection of files just in one event?

Upvotes: 0

Views: 984

Answers (3)

Steve Wellens
Steve Wellens

Reputation: 20640

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.

Upvotes: 0

Austin Salonen
Austin Salonen

Reputation: 50235

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.

Upvotes: 1

oberfreak
oberfreak

Reputation: 1807

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.

Upvotes: 0

Related Questions