CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2012
    Posts
    6

    Talking Visual Basic 2010 displaying RAM usage.

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Basic 2010 displaying RAM usage.

    Please explain what you mean. Do you mean the SIZE of the file?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2012
    Posts
    6

    Re: Visual Basic 2010 displaying RAM usage.

    Just the overall memory usage of the computer.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Basic 2010 displaying RAM usage.

    Really doesn't matter anymore, with SWAP FILES and all. Perhaps if you told exactly what the problem that you're having, or trying to solve?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jan 2012
    Posts
    6

    Re: Visual Basic 2010 displaying RAM usage.

    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.

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Visual Basic 2010 displaying RAM usage.

    Is this what you are looking for ?

    http://www.tek-tips.com/faqs.cfm?fid=5655

    or perhaps this would help
    http://www.neowin.net/forum/topic/61...-memory-usage/
    Last edited by DataMiser; January 19th, 2012 at 02:28 AM.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Visual Basic 2010 displaying RAM usage.

    see if you like this (attached vs 2010 project):
    Code:
    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
    Attached Files Attached Files
    ...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.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Basic 2010 displaying RAM usage.

    PS: Much easier in Powershell

    Code:
    while ($true)
    {
    Start-Sleep -s 15
    cls
    ‘CPU Load is’ Get-WmiObject win32_processor | select LoadPercentage  |fl
    }
    Updates every 15 seconds
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Visual Basic 2010 displaying RAM usage.

    Powershell
    and you could also get info about ram:
    http://mintywhite.com/windows-7/7mai...ick-windows-7/
    but this is vb.net forum...
    so you should call wmi through net, like here:
    http://ondotnet.com/pub/a/dotnet/2003/04/07/wmi.html
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured