Ive got a service that runs just fine, but I want it to be able to terminate itself if the startup parameters are invalid. The service uses a timer to trigger its functionality. This is what Ive got so far...
In the OnStart event, I read and validate the startup params. If invalid, I set the validConfig flag to false. At the end of OnStart, I start the services timer.
In the Elapsed event for the timer, I check the validConfig flag. If False then I do this:
Dim sc As New ServiceController(Me.ServiceName)
sc.Stop
---
But I always get an exception that I couldnt attach to the service. (I even tried attaching to another service, just to see if it would work, but I get the same exception.)
What am I missing? How do you tell a service to stop itself? Thanks.
Jerry
In the OnStart event, I read and validate the startup params. If invalid, I set the validConfig flag to false. At the end of OnStart, I start the services timer.
In the Elapsed event for the timer, I check the validConfig flag. If False then I do this:
Dim sc As New ServiceController(Me.ServiceName)
sc.Stop
---
But I always get an exception that I couldnt attach to the service. (I even tried attaching to another service, just to see if it would work, but I get the same exception.)
What am I missing? How do you tell a service to stop itself? Thanks.
Jerry