Hai
How to check service is running or not after service is stopped or started ?
in my website i have 2 buttons for stop and other for start service,if stop or start service i will redirect the same page,in page load i will check service is running or not,if runninge i will show "Started" word in label and one started image,if it stopped i will show "Paused" word in label and one paused image.
But actually sometimes show both image and my codes is
Private Sub sampleService()
imgbtnPlay.Visible = False
imgbtnPause.Visible = False
Dim myController As ServiceController
myController = New ServiceController("sample Service")
Thread.Sleep(3000)
If myController.Status = ServiceControllerStatus.Stopped Then
imgbtnPlay.Visible = True
imgbtnPause.Visible = False
lblStatus.ForeColor = Color.Red
lblStatus.Text = "Paused"
ElseIf myController.Status = ServiceControllerStatus.Running Then
imgbtnPause.Visible = True
imgbtnPlay.Visible = False
lblStatus.ForeColor = Color.Green
lblStatus.Text = "Started"
End If
End Sub
why both image(imgbtnPause and imgbtnPlay) appears same time ?this function in page load event and when start or stop button clicked page is redirect to same page.
Follows codes are 2 image button click event
Protected Sub imgbtnPause_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs) Handles imgbtnPause.Click
Dim myController As ServiceController
myController = New ServiceController("sample Service")
If myController.Status = ServiceControllerStatus.Running Then
While myController.Status = ServiceControllerStatus.Running
myController.Stop()
imgbtnPause.Visible = False
imgbtnPlay.Visible = True
lblStatus.ForeColor = Color.Red
lblStatus.Text = "Paused"
myController.Refresh()
End While
End If
Response.Redirect("Dashboard.aspx")
End Sub
And this is for Play button click event
Protected Sub imgbtnPlay_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs) Handles imgbtnPlay.Click
Dim myController As ServiceController
myController = New ServiceController("sample Service")
If myController.Status = ServiceControllerStatus.Stopped Then
While myController.Status = ServiceControllerStatus.Stopped
myController.Start()
imgbtnPause.Visible = True
imgbtnPlay.Visible = False
lblStatus.ForeColor = Color.Green
lblStatus.Text = "Started"
myController.Refresh()
End While
End If
Response.Redirect("Dashboard.aspx")
End Sub
May be behave like this,if i start service,it redirect same page and service is checking,if code pass through IF part ,service is not start so it show pause image ,then it pass else-if part that time service is running so it executes else-if part also,in that service is running,it show play image.i think if and else-if satisfy that condition so it executes both part so only it show both image.Bcz if service is start or stop immediately not affect in service ,it take time.
Regards
Aravind