【问题标题】:VB.NET using ProcessNameVB.NET 使用 ProcessName
【发布时间】:2015-10-16 09:29:51
【问题描述】:

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

运行 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 时,谁能帮我计算一下?

【问题讨论】:

  • 您的代码仅在触发Form1_Load() 时检查calc.exe 是否打开。您将需要定期检查进程状态以更新标签。您可能想要使用 Timer 控件
  • 我忘记了使用计时器功能的新代码,但与 Form1_Load() 相同

标签: vb.net visual-studio-2012


【解决方案1】:

如果您要投票,那么就这样做:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多