I have a service that stops as soon as it starts. I want it to wait for events to be triggered by the filesystemwatchers that i have setup, can it be done?
You'll need to create another thread to do the real work of your service. The OnStart and OnStop methods are called from the context of the Service Control Manager (the GUI tool you use to control services). Execution returns to the SCM after those events, so you can't use them for your service's activity.
I have a service that monitors a directory for a file and performs operations when a file is dropped there. I have a FileSystemWatcher object (must be module level) that is instantiated in the OnStart Sub. I am not explicitly starting a new thread, although I am not positive what is going on behind the scenes with this object.
Either way, the service shouldn't just be stopping automatically. I was having this problem for a while, and it was caused by an unhandled error occuring in OnStart. Put a Try Catch block around your code in the OnStart. You can write the errors to the event log using the EventLog object. This helped me work through the problems, and now everything works great.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.