if x new files are simultaneously created in the folder being monitored, does the Created event fire x times at the same time or x times one after the other?
-
For one, how would you simultaneously create x new files in the same instant? There'd be lag. Then we get to the subject of whether or not the event is being fired from many threads each running on a different core all syncing up and firing exactly at the same time... seems unlikely. I can't see than anything would happen "at the same time", but maybe I misunderstand the question. – spender Oct 02 '12 at 12:37
-
you are right. it won't happen at the same time. But if you create 10 empty text documents and move them to the folder being monitored, then they are being created almost simultaneously... at least from the point of view of a human being. In any case, the part that worries me is the code inside the event handler procedure, which can spend as much a minute processing each file. I don't want all this processing to happen at the same time. – John Smith Oct 02 '12 at 12:50
-
Sounds like you need a queue. – spender Oct 02 '12 at 12:51
2 Answers
The filesystemwatcher class uses an internal buffer to store filechanges (this can overflow, which will cause events to be lost) which will invoke events of the subscribed type one after the other in succession until the buffer is empty. This is run asynchronous by default. Default is used as long as long as the SynchronizingObject property is described in the documentation. You can make this behave synchronously by setting a SynchronizingObject as is described in this answer.
Note also, from the documentation, that only one file watcher will receive the event of a file change even if more than one is watching the same folder.
In summary: By default, these events are stored in a buffer and then fired in rapid succession by a separate thread until the buffer is empty. If many files are created or changed too fast, some changes may be lost due to buffer overflow.

- 1
- 1

- 365
- 1
- 9
It fires x
times at the same time. You could have the Created
event running at the same time for multiple files.

- 1,023,142
- 271
- 3,287
- 2,928