I'm using a ServiceControll er to try to stop and start a service. For development, I've been using the Apache service to experiment with.
I have a simple windows form in vb.net with a start and a stop button, along with a servicecontroll er added to the form.
The start button calls ServiceControll er1.Start and the stop button ServiceControll er1.Stop. Each works individually.
However, if I start the service with one button and then wait and try to stop it, it doesn't do anything. Or, if I stop the service with the stop button and then try to start, again nothing happens.
If I close the application and then reopen it, it will either stop or start the service. But not stop AND start.
Do you have any idea why this would be?
Here's the code:
I have a simple windows form in vb.net with a start and a stop button, along with a servicecontroll er added to the form.
The start button calls ServiceControll er1.Start and the stop button ServiceControll er1.Stop. Each works individually.
However, if I start the service with one button and then wait and try to stop it, it doesn't do anything. Or, if I stop the service with the stop button and then try to start, again nothing happens.
If I close the application and then reopen it, it will either stop or start the service. But not stop AND start.
Do you have any idea why this would be?
Here's the code:
Code:
Private Sub btnStartService_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartService.Click
If (ServiceController1.Status.ToString <> "Running") Then
ServiceController1.Start()
End If
End Sub
Private Sub btnStopService_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopService.Click
If ServiceController1.Status.ToString <> "Stopped" Then
ServiceController1.Stop()
End If
End Sub
Comment