在vb,asp.net中停止或启动服务后,如何检查服务是否正在运行? [英] How to check Service is running or not after service is stopped or started in vb ,asp.net ?

查看:66
本文介绍了在vb,asp.net中停止或启动服务后,如何检查服务是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai

服务停止或启动后如何检查服务是否正在运行?



在我的网站上我有2个按钮对于停止和其他启动服务,如果停止或启动服务我将重定向同一页面,在页面加载我将检查服务是否正在运行,如果runninge我将在标签中显示已启动字和一个启动图像,如果它我会在标签上显示Paused字样并暂停一张图片。



但实际上有时显示图像和我的代码是

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



为什么两个图像(imgbtnPause和imgbtnPlay)同时出现?这个函数在页面加载事件中,当开始或停止按钮点击页面重定向到同一页面。

关注代码是2图片按钮点击事件


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"
                ' Thread.Sleep(3000)
                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"
                '  Thread.Sleep(3000)
                myController.Refresh()
            End While
        End If
  Response.Redirect("Dashboard.aspx")
    End Sub







可能表现得像这个,如果我开始服务,它重定向相同的页面和服务正在检查,如果代码通过IF部分,服务没有启动所以它显示暂停图像,然后它传递其他 - 如果部分时间服务正在运行,所以它执行其他 - 如果部分也在,该服务正在运行,它显示播放图像。我认为if和else-如果满足该条件所以它执行两个部分所以只显示image.Bcz如果服务启动或立即停止不影响服务,需要时间。

问候

Aravind




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

推荐答案

其中一个原因可能是您所共享的代码只有状态检查已完成停止并且正在运行,而状态可能处于暂停状态,停止,暂停,开始等等。尝试调试并查看服务是否处于任何这些状态并处理这些状态。
One of the reason can be as per the code you shared only Status checking is done for Stopped and running while there are chances of status can be in Paused,stoppending,pausepending,startpending etc. Try to debug and see whether the service is in any of these status and handle those status too.


这篇关于在vb,asp.net中停止或启动服务后,如何检查服务是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆