我有以下内容:
Dim plist() As Process = Process.GetProcesses()
For Each prs As Process In plist
ListBox1.Items.Add(prs.ProcessName + " (" + (prs.PrivateMemorySize64 / 1024000).ToString() + " MB)")
但是如果可能的话,id真的想通过内存大小来列出它吗?如果有人有任何想法,将非常感激
答案 0 :(得分:0)
这是一个基本示例,您必须根据自己的需要进行自定义。
Public Class Form1
'
Dim pList() As Process = Nothing
'
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'
Dim pItem As Process = Nothing
Dim pCounter As Integer = Nothing
'
pList = Process.GetProcesses()
For pCounter = 0 To pList.Count - 1
pItem = pList(pCounter)
ListBox1.Items.Add(pItem.ProcessName + " (" + (pItem.PrivateMemorySize64 / 1024000).ToString() + " MB)") '
Next
'sort list
SortProcessList()
'
End Sub
'
Sub SortProcessList()
'
Dim i As Integer
Dim j As Integer
Dim pTmp As Process
'
'sort list based on lowest usage first
For i = 0 To pList.Count - 2
For j = i + 1 To pList.Count - 1
If pList(i).PrivateMemorySize64 > pList(j).PrivateMemorySize64 Then
pTmp = pList(i)
pList(i) = pList(j)
pList(j) = pTmp
End If
Next
Next
ReloadSortedList()
'
End Sub
Sub ReloadSortedList()
'
Dim pItem As Process = Nothing
Dim pCounter As Integer = Nothing
'
ListBox1.Items.Clear()
For pCounter = 0 To pList.Count - 1
pItem = pList(pCounter)
ListBox1.Items.Add(pItem.ProcessName + " (" + (pItem.PrivateMemorySize64 / 1024000).ToString() + " MB)") '
Next
'tidy up
pItem = Nothing
pCounter = Nothing
'
End Sub
End Class