I am going to implement the archetypal solution FileSystemWatcher. I have a directory for monitoring the creation of files, as well as the task of sucking the created files and inserting them into the database. Roughly this will be related to reading and processing 6 or 7, 80 char text files that appear at a speed of 150 ms in packets that occur every couple of seconds, and rarely you need to process a 2 MB binary. This will most likely be a 24/7 process.
From what I read about the FileSystemWatcher object, it’s better to insert its events in one thread and then delete or process them in another thread. The premonition that I have now is the best thread creation mechanism that performs processing. The options that I see are as follows:
Every time I get an FSW event, I manually create a new thread (yes, I know, stupid architecture, but I had to say that).
Throw processing to the CLR thread pool whenever I receive an FSW event
At startup, create a dedicated second thread for processing and use the producer / consumer model to process the work. The main thread places the request, and the second thread deletes it and does the work.
I am inclined to the third method as preferred, because I know that a working thread will always be needed, and probably also because I don’t feel the thread pool.
source
share