VB.NET使用ProcessName

时间:2015-07-25 23:17:40

标签: vb.net visual-studio-2012

我创建了一个程序,其函数按进程名称读取应用程序......

当运行Calc.exe时,Label31从CLOSE更改为OPEN,但是当我关闭Calc.exe Label31时,不希望从OPEN更改回CLOSE ...

我的代码

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim myProcess() As Process = System.Diagnostics.Process.GetProcessesByName("calc")
    For Each Read As Process In myProcess
        Label31.Text = "OPEN"
    Next
End Sub

当封闭的label31从OPEN变为CLOSE时,任何人都可以帮助我如何计算?

1 个答案:

答案 0 :(得分:0)

如果您投票,请执行以下操作:

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    Dim myProcess() As Process = System.Diagnostics.Process.GetProcessesByName("calc")
    Label31.Text = If(myProcess.Length > 0, "OPEN", "CLOSED")
End Sub