I've been looking at different ways of getting processes and updating them. I first looked at WMI and then decided to just use the Process Class.
I found some code on another web site that shows how to update processes in a ListBox. Ideally, I'd like to use a listview.
I've been trying for a couple of days on how to get this to work, but I've come up short. If you all can help me understand the process, I'd appreciate it.
The original poster created a class first and then updated the processes within a timer I believe. I tested it with a listbox, and it works well. The process is surprisingly smooth.
vb.net Code:
Class proc Public name As String Public Id As Integer Overrides Function ToString() As String Return name End Function End Class
vb .net Code:
Private Sub UpdateProcesses() proclist = Process.GetProcesses() For Each p As Process In proclist Dim p2 As New proc p2.name = p.ProcessName p2.Id = p.Id Dim add As Boolean = True For Each pr As proc In ListBox1.Items If (pr.Id = p.Id) Then add = False End If Next If add Then ListBox1.Items.Add(p2) End If Next Dim l As New ListBox() Dim b As New ListBox.ObjectCollection(l, ListBox1.Items) For Each p As proc In b Try Dim p2 As Process = Process.GetProcessById(p.Id) Dim s = p2.ProcessName Catch ex As Exception ListBox1.Items.Remove(p) End Try Next End Sub
Thanks![]()




Reply With Quote