Skip to content

VB.Net Monitor Process

January 24, 2012

ReadOnly tIsProcessRunning As New Timer(1000)

Private Sub Main()
    AddHandler tIsProcessRunning.Elapsed, New ElapsedEventHandler(AddressOf tIsProcessRunning_Tick)
    If Not IsProcessRunning() Then
        tIsProcessRunning.Enabled = True
    End If
End Sub

Private Function IsProcessRunning() As Boolean
    IsProcessRunning = False
    For Each p As Process In Process.GetProcesses
        If p.ProcessName.StartsWith("Process Name") Then
            p.EnableRaisingEvents = True
            AddHandler p.Exited, AddressOf Process_Exited
            IsProcessRunning = True
            Exit For
        End If
    Next
End Function

Private Sub Process_Exited(ByVal sender As Object, ByVal e As EventArgs)
    tIsProcessRunning.Enabled = True
End Sub

Private Sub tIsProcessRunning_Tick(ByVal sender As Object, ByVal e As EventArgs)
    tIsProcessRunning.Enabled = False
    If Not IsProcessRunning() Then
        tIsProcessRunning.Enabled = True
    End If
End Sub
'
Advertisements

From → .Net

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: