如何在运行所需进程时更改标签

时间:2017-03-10 19:49:46

标签: vb.net

我正在尝试检查进程是否正在运行,然后以文本形式在应用程序中显示它。在这种情况下如果找不到进程,应用程序将显示“未找到进程”与其运行时“进程正在运行”...

Example

这是我目前的代码:

B17

1 个答案:

答案 0 :(得分:0)

经过无休止的搜索,人们几乎无益,100%的选票,我终于向你提出了解决方案!适用于VB.Net!简单制作标签,插入此代码。繁荣。所有代码都是ReadWritingMemory.vb中的原始代码。

Public Class Form1
Dim Timer1 As New Timer

    Public Function IsProcessRunning(Notepad As String) As Boolean
        For Each clsProcess As Process In Process.GetProcesses()
            If clsProcess.ProcessName.StartsWith(Notepad) Then
                Return True
            Else
            End If
        Next
        Return False
    End Function
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim Run As Integer
        If Run = 0 Then
            AddHandler Timer1.Tick, AddressOf Timer1_Tick
            Timer1.Interval = 1
            Timer1.Start()

        Else
            RemoveHandler Timer1.Tick, AddressOf Timer1_Tick
            Timer1.Stop()
        End If
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs)
        Dim p() As Process
        p = Process.GetProcessesByName("notepad")
        If p.Count > 0 Then
            Label1.Text = "Status: Notepad Running!"
            Label1.Refresh()
        Else
            Label1.Text = "Status: Notepad Not Running!"
            Label1.Refresh()
        End If
    End Sub
End Class

请确保将ReadWritingMemory.vb添加到您的班级。 找到的代码here

视觉背景:

Example 1: Not running Example 1: running