Thanks very much cody. I have done as you said, and the refresh rate is now
acceptable. However, when the list view refreshes, the application consumes
up to 95 percent of CPU resources. This is not acceptable at all. How should
I avoid my application to be quiet like Windows task manager which goes only
upto 4 percent in each refresh session.
Public Overridable Sub UpdateDate()
On Error Resume Next
Dim ListItemsArr(Me.ProcessMain.GetProcesses.Length) As ListViewItem
Dim i As Integer = 0
For Each process As System.Diagnostics.Process In
Me.ProcessMain.GetProcesses
Dim ListItem As New ListViewItem(process.ProcessName)
With ListItem
.SubItems.Add(process.MainModule.FileName)
.SubItems.Add(process.PriorityClass.ToString)
.SubItems.Add(process.TotalProcessorTime.ToString)
.SubItems.Add(process.PagedMemorySize)
.SubItems.Add(process.NonpagedSystemMemorySize)
.SubItems.Add(process.Modules.Count)
.SubItems.Add(process.MainModule.FileVersionInfo.C ompanyName)
End With
ListItemsArr(i) = ListItem
i += 1
Next
Dim selIndex As Integer
If ListView1.Items.Count > 0 Then
If Me.ListView1.SelectedItems.Count > 0 Then
selIndex = Me.ListView1.SelectedIndices(0)
End If
Me.ListView1.Items.Clear()
End If
ListView1.BeginUpdate()
Me.ListView1.Items.AddRange(ListItemsArr) < --- here is what you
told me...
ListView1.ListViewItemSorter = New
MyListViewSorter(Me._ColumnClicked)
ListView1.EndUpdate()
Me.ListView1.Items(selIndex).Selected = True
End Sub
"cody" <de********@gmx.de> wrote in message
news:Oe*************@tk2msftngp13.phx.gbl...
Add all items to an Array and then use ListViewItem.Items.AddRange() this
is much faster.
"?BOT NET>" <BOTTED@ERTYU> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP12.phx.gbl... Why is the following code so slow? I have a listView that must refresh
it's
processes data every 3 seconds. However, this sometimes goes beyond 5
seconds and crashes the application. I have tries multi-threading, also
ListView.BeginUpdate + EndUpdate(), but the code is sooo slow. Try it for
yourself:
Public Sub UpdateData()
On Error Resume Next
Me.ListView1.Clear()
For Each process As System.Diagnostics.Process In
Me.Process1.GetProcesses()
Dim ListItem As New ListViewItem(process.ProcessName)
With ListItem
.SubItems.Add(process.MainModule.FileName)
.SubItems.Add(process.TotalProcessorTime.ToString( ))
.SubItems.Add(process.PriorityClass.ToString())
.SubItems.Add(process.PagedMemorySize)
.SubItems.Add(process.NonpagedSystemMemorySize)
.SubItems.Add(process.Modules.Count)
.SubItems.Add(process.MainModule.FileVersionInfo.C ompanyName)
End With
Me.ListView1.Items.Add(ListItem)
Next
End Sub
Any help is greatly appreciated.