FileSystemWatcher Windows Service

  • Thread starter Thread starter Craig Thompson
  • Start date Start date
C

Craig Thompson

I've attempted to write a windows service that creates one FileSystemWatcher
for each entry in a XML config file. Everything start perfrectly and runs
as I expect for about 5 minutes and then after that the FileSystemWatchers
seem to stop monitoring... My theory is that for some reason the Garbage
Collector is trashing my FileSystemWatchers.

Another clue to my situation is that I just took my service and made it into
a windows form application and it's been running overnight without any
problems. What am I overlooking? Can anyone point me in the right
direction?

Thanks,

Craig
 
Craig,
I have been using watcher in windows service. Sometimes when you start a
program from the watching event and that program breaks, the whole watcher
service appear to break. If you attach the debugger to windows service, you
would find out that the main window service thread would be stuck in some
other part of program, thus ignoring further watcher interrupts. To make
sure all watcher events are always handled, I write a very small process
which just pushes the required info in SQL Server table and relinquish the
control back to listener. The time consuming main program then looks in the
SQL Server table, pops off the watcher generated rows, and process them at
its Owen convenience reducing the risk of overlooking watcher event.

Fakher Halim
 
Just to follow-up for anyone who runs into this problem in the future...
Fakher's suggestion worked. I changed my service to only execute a stored
procedure that writes a record to a SQL table when a FileSystemWatcher event
is triggered. Then periodically, I have another thread on the service that
looks at this table for new files to process. This seems to have freed up
the FileSystemWatcher thread and my service does not mysteriously stop
anymore...

Craig
 
Back
Top