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:
  1. Class proc
  2.         Public name As String
  3.         Public Id As Integer
  4.         Overrides Function ToString() As String
  5.             Return name
  6.         End Function
  7.     End Class

vb .net Code:
  1. Private Sub UpdateProcesses()
  2.         proclist = Process.GetProcesses()
  3.         For Each p As Process In proclist
  4.             Dim p2 As New proc
  5.             p2.name = p.ProcessName
  6.             p2.Id = p.Id
  7.             Dim add As Boolean = True
  8.             For Each pr As proc In ListBox1.Items
  9.                 If (pr.Id = p.Id) Then
  10.                     add = False
  11.                 End If
  12.             Next
  13.             If add Then
  14.                 ListBox1.Items.Add(p2)
  15.             End If
  16.         Next
  17.         Dim l As New ListBox()
  18.         Dim b As New ListBox.ObjectCollection(l, ListBox1.Items)
  19.         For Each p As proc In b
  20.             Try
  21.                 Dim p2 As Process = Process.GetProcessById(p.Id)
  22.                 Dim s = p2.ProcessName
  23.             Catch ex As Exception
  24.                 ListBox1.Items.Remove(p)
  25.             End Try
  26.         Next
  27.     End Sub

Thanks