Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi people, just signed up to the forum :D. need a little help with a section of my code for a project I am doing. my RAM monitor doesn't seem to work properly and sometimes doubles the value or displays a incorrect value when put against task manager. the code I am using is below:

VB
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    Dim SystemRAM As Integer = CDec(PerformanceCounter3.NextValue.ToString())        
    Dim SystemRAM2 As Integer

    SystemRAM2 = 80 - SystemRAM                                                      
    Label34.Text = SystemRAM2.ToString() & " %"                                        
    On Error Resume Next                                                             
    ProgressBar3.Value = SystemRAM2.ToString
End Sub


hope someone can help ???

cheers
ElmoK11
Posted
Updated 24-Jan-11 6:29am
v2

1 solution

Without seeing how PerformanceCounter3 is created, it is difficult to give much help.

You might also, for your own benefit in the future, consider using more descriptive names for your variables. In 6 months time you probably won't remember what 'PerformanceCounter3' does, whereas you probably would remember what 'RAMPerformanceCounter' is for.

[Edit]
After your answer/comment:

It is not obvious to me why you are calculating 80 - SystemRAM (That doesn't mean it is wrong, just that I cannot understand where the 80 comes from :) ) but it looks like you are trying to get Available Memory.

If so have you tried something like:
category name: memory
counter name: Available MBytes
generate member:true
instance lifetime: Global
modifiers: friend


to see if that fluctuates as well

[/Edit]
 
Share this answer
 
v2
Comments
Sandeep Mewara 24-Jan-11 13:35pm    
Comment from OP:
performance counter 3 is set to:

category name: memory
counter name: % committed bytes in use
generate member:true
instance lifetime: Global
modifiers: friend

i have not got round to naming the counters sorry. only been on it for about 2 days. hope this helps?

cheers
ElmoK11 24-Jan-11 13:46pm    
performance counter 3 is set to:

category name: memory
counter name: % committed bytes in use
generate member:true
instance lifetime: Global
modifiers: friend

i have not got round to naming the counters sorry. only been on it for about 2 days. hope this helps?

cheers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900