Monitoring a directory for new file creation without FileSystemWatcher

前端 未结 8 699
臣服心动
臣服心动 2021-01-31 06:51

I have to create a Windows service which monitors a specified folder for new files and processes it and moves it to other location.

I started with using FileSyste

8条回答
  •  独厮守ぢ
    2021-01-31 07:16

    Actually, the FileWatcher component is not 100% "stable" from my experience over the years. Push enough files into a folder and you will lose some events. This is especially true if you monitor a file share, even if you increase the buffer size.

    So, for all practical reasons, use FileWatcher together with a Timer which scans a folder for changes, for the most optimal solution.

    Examples of creating Timer code should be in abundance if you google it. If you keep track of the last DateTime when the timer ran, then check the modified date of each file, and compare it to the date. Fairly simple logic.

    The timer interval depends of how urgent the changes are for your system. But check every minute should be fine for many scenarios.

提交回复
热议问题