I have a simple windows form in vb.net with a start and a stop button, along with a servicecontroller added to the form.
The start button calls ServiceController1.Start and the stop button ServiceController1.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:
Expand|Select|Wrap|Line Numbers
- 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