Hello. I am developing a program in vb.net that finds some processes, takes the PID from them, and then collects some information about them.
The problem is when you have 2 equal processes. In that case, I would need it to see which one is currently using more memory, and delete the other one from the listbox. My code for finding the PID's:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TopMost = True
Me.Focus()
For Each Proc As Process In Process.GetProcesses()
ListBox1.Items.Add(Proc.ProcessName)
ListBox2.Items.Add(Proc.Id)
Proc.Start()
Next
Private Sub Proc_Tick(sender As Object, e As EventArgs) Handles Proc.Tick
'variáveis
Dim actualProcess as String
Dim ListBox1Items as String
Dim actualProcessExists as Boolean = False
Dim ProcID as Integer
'----------------------------------------------
actualProcess = "explorer"
ListBox1Items = ListBox1.Items.Count - 1
'Checando se o processo existe
For ia As Integer = ListBox1Items To 0 Step -1
ListBox1.SelectedIndex = ia
If ListBox1.SelectedItem = actualProcess Then
actualProcessExists = True
Else
Proc.Stop()
Proc2.Start()
End If
Next
'----------------------------------------------------------
'Adicionando PID à outra ListBox
If actualProcessExists = True Then
For i As Integer = ListBox1Items To 0 Step -1
ListBox1.SelectedIndex = ia
If ListBox1.SelectedItem = actualProcess Then
ListBox2.SelectedIndex = ListBox1.SelectedIndex
ProcID = ListBox2.SelectedItem
ListBox3.Items.Add(ProcID)
Else
Proc.Stop()
Proc2.Start()
End if
End Sub
Well, what I needed was that when I saw 2 items in ListBox2, it, via the process PIDs, would see which one uses the most memory, and would define this as "ProcID". Could you help me?
Thank you in advance.