Hi, All,
I am instructed to develop a console application which monitors a process. It is now done but the problem is when I'm running it the CPU usage increases up to 100%, kindly check below code for some enhancement:
Console App:
Sub Main()
While True
System.Threading.Thread.Sleep(1000)
If IsProcessExist() = False Then Exit While
End While
End Sub
Private Function IsProcessExist() As Boolean
IsProcessExist = False
Dim psList() As Process
psList = Process.GetProcessesByName("pnavigator")
For Each p As Process In psList
If p.Id = CDbl(cid) Then
IsProcessExist = True
If p.MainWindowTitle.ToUpper.StartsWith("IDLE") Then
IsProcessExist = False
End If
Exit For
End If
Next p
End Function
Thanks in advance.