All I am looking to do is display the current RAM usage being used in a textbox, nothing more nothing less. I will encorperate it into a timer and update automatically, how do I do this ?
I run servers with 32GB's of RAM, I want to run a visual basic "coded" program to monitor the RAM usage and put it in a listbox, i have already done it with CPU usage, I just want to know how to do it with RAM.
Public Class frmWinCounter
Protected cpuCounter As System.Diagnostics.PerformanceCounter
Protected ramCounter As System.Diagnostics.PerformanceCounter
Protected tmr As System.Timers.Timer
Sub New()
' This call is required by the designer.
InitializeComponent()
tmr = New System.Timers.Timer(500)
AddHandler tmr.Elapsed, AddressOf Me.tmr_Elapsed
' Add any initialization after the InitializeComponent() call.
cpuCounter = New System.Diagnostics.PerformanceCounter()
cpuCounter.CategoryName = "Processor"
cpuCounter.CounterName = "% Processor Time"
cpuCounter.InstanceName = "_Total"
ramCounter = New System.Diagnostics.PerformanceCounter("Memory", "Available MBytes")
'init cpu counter
Dim tmp As Single = cpuCounter.NextValue()
End Sub
Private Sub btnCheckRamCpu_Click(sender As System.Object, e As System.EventArgs) Handles btnCheckRamCpu.Click
tmr.Enabled = Not tmr.Enabled
If tmr.Enabled Then
btnCheckRamCpu.Text = "Stop monitor ram cpu"
Else
btnCheckRamCpu.Text = "Start monitor ram cpu"
End If
End Sub
Private Delegate Sub dlgUpdateUI(ByVal ctl As Control, ByVal text As String)
Private Sub tmr_Elapsed(sender As Object, e As Timers.ElapsedEventArgs)
Dim cpumsg As String = "Cpu usage: " & cpuCounter.NextValue().ToString("#0") + "%"
Dim rammsg As String = "Ram usage: " & ramCounter.NextValue().ToString("###,###,##0") + " Mb"
If Me.InvokeRequired Then
Dim d As New dlgUpdateUI(AddressOf SetLblText)
Me.Invoke(d, lblCpu, cpumsg)
Me.Invoke(d, lblRam, rammsg)
Else
SetLblText(lblCpu, cpumsg)
SetLblText(lblRam, rammsg)
End If
End Sub
Private Sub frmWinCounter_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
tmr.Enabled = False
End Sub
Private Sub SetLblText(lbl As Label, sText As String)
lbl.Text = sText
End Sub
End Class
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Last edited by Cimperiali; January 28th, 2012 at 08:14 PM.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.