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 FileSystemWatcher
. My boss doesn't like FileSystemWatcher
and wants me to use polling by using a Timer
or any other mechanism other than FileSystemWatcher
.
How can you monitor directorying without using FileSystemWatcher
using .NET framework?
At program startup, use Directory.GetFiles(path) to get the list of files.
Then create a timer, and in its elapsed event call hasNewFiles:
In the calling code, you'll have new files if:
edit: if you want a more linqy solution:
1) Sounds like your boss is an idiot
2) You will have to use functions like Directory.GetFiles, File.GetLastAccessTime, etc and keep it in memory to check if it changed.