Hi,
I write an application which waits for incomming files in a specified
directory. I thought, that using the FileSystemWatcher would be the best, as
it does exactly what I need.
But now I have a problem:
I wonna get shure, that really all files are processed and I need to be
shure, that no file is processed twice.
If my application is started while there are already files in the directory
(which is realistic, as the application could be restarted, but the
application which produces the files may not be stopped at the same time). So
I thouhgt about just reading all the files which are already in the directory
and then starting the FileSystemWatcher for the new files which are arriving.
But what if a file arrives while I'm processing the old ones? So I thought
about first starting the FileSystemWatcher and then processing the old files.
But know I have the problem, that between starting the a file could be
processed twice (in a worst case cenario, where a new file arrives between
starting the FileSytemWatcher and reading the old files).
Maybe I'm just thinking to much, but is there any clean way to solve the
problem? Can I use the FileSystemWatcher instance for getting the old files
somehow?
The only solution I came up with, is to forget about the filesystemwatcher
and use a timer which checks for new files. But as there may be a longer time
period with no new files it would not be the best solution, because I would
have to let the timer look for new files about every 3 to 5 seconds, as some
of the files are time critical.
Maybe someone of you has a solution for my worst case thinking.
greetings
Florian