hier ist ein code zum abfragen des speicherstatus in einer konsolenanwendung:
VB.NET-Quellcode
- Module Module1
- Sub Main()
- Dim s As String ' Zeichenfolge für die Ausgabe
- Dim strTPM, strAPM As String ' Total/Available Physical Memory
- Dim strTVM, strAVM As String ' Total/Available Virtual Memory
- Dim widthTotal As Integer ' Hilfsariable für die Ausrichtung der Ausgabe
- ' Speicherausstaung und - belegung ermitteln
- With My.Computer.Info
- strTPM = String.Format("{0:#,##0}", .TotalPhysicalMemory / 1024)
- strAPM = String.Format("{0:#,##0}", .AvailablePhysicalMemory / 1024)
- strTVM = String.Format("{0:#,##0}", .TotalVirtualMemory / 1024)
- strAVM = String.Format("{0:#,##0}", .AvailableVirtualMemory / 1024)
- End With
- 'Benötigte Spaltenbreite ermittlen
- If strTPM.Length > strTVM.Length Then
- widthTotal = strTPM.Length
- Else
- widthTotal = strTVM.Length
- End If
- 'Zeichenfolge für die Ausgabe zusammenstellen
- s = "Aktueller Speicherstatus (in KByte):" & vbCrLf & vbCrLf 'Titelzeile
- s &= " physikalisch: " & strTPM.PadLeft(widthTotal) ' Physikalischer Speicher
- s &= " (" & strAPM & " frei)" & vbCrLf
- s &= " virtuell :" & strTVM.PadLeft(widthTotal) ' Virtueller Speicher
- s &= " (" & strAVM & "frei)" & vbCrLf
- 'Ausgabe auf dem Bildschirm
- Console.WriteLine(s & vbCrLf)
- Console.ReadKey()
- End Sub
- End Module