简体   繁体   中英

VB.NET using ProcessName

I created a program with functions read an application by process name ...

When Calc.exe is run Label31 changed from CLOSE into the OPEN, but when I close Calc.exe Label31 do not want to change back from OPEN into the CLOSE...

My Code

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

anyone can help me how to calc when closed label31 changed from OPEN into CLOSE?

If you're polling then just do:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM