简体   繁体   中英

does System.IO.FileSystemWatcher's Created event fire synchronously or asynchronously?

如果在被监视的文件夹中同时创建了x个新文件,则Created事件是同时触发x次还是依次触发x次?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM