I want to collect the path of the files as soon as any file is created in a particular folder.
I used a List<string>
and the FileSystemWatcher
component. I add the paths to the List
in the Created
event, and everything works fine.
However, when there are many small files created, say around 2000, the Created
event is fired only 1200 times. When I don't add the path to the list in the Created
event, though, it is called for 2000 times. I tried using a separate thread, but to no avail.
How can I enable FileSystemWatcher
to fire each and every event without missing some of the events?
Be sure to implement the Error event so you know when things go wrong. Keep the notification event handlers short and snappy, just add the file to a list and get out. Process the list in another worker thread. Increasing InternalBufferSize can help but should be avoided.