1
Hello. I’m developing a Vb.net program that finds some processes, takes their PID, and then collects some information about them.
The problem is when you have two equal processes. In that case, I would need him to see which of the two is using the most memory at the moment, and delete the other from the listbox. My code to find the Pids:
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 two items on Listbox2, he, by the PID’s of the processes, saw which uses more memory, and defined this one as "Procid". Could you help me?
Thank you in advance.
I edited it. I forgot to put the "Form_load" in the code, then I couldn’t understand the code of the timer...
– Happy
Because it uses two
ListBox
? What is the purpose of your code?– João Martins
In the first, all processes that are currently running will be added. In the second, the PIDS of these processes will be added. Then using FOR, it changes the selectedindex of listbox1, which contains all processes, and checks if the selected item matches the "actualProcess" variable, if it matches, it will set the selectedindex of listbox2 to the same selectedindex of listbox1, and then we’ll have the pid of the process. And then the process pid will be added to listbox3. (I edited the code)
– Happy