Results 1 to 8 of 8

Thread: PerformanceCounter question.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    PerformanceCounter question.

    I have a function that will get the present upload and download rate of my current connection.

    It is working now here is my code used:

    Code:
     
            Dim NetSent As New System.Diagnostics.PerformanceCounter
            Dim NetReceived As New System.Diagnostics.PerformanceCounter
    
    
            Dim KBytesSent As Long
            Dim KBytesReceived As Long
    Do Until Me._Stop
                    KBytesSent = Convert.ToInt32(Math.Round(NetSent.NextValue / 1024, 0, MidpointRounding.AwayFromZero))
                    Me.StatusUP.Text = KBytesSent & " kB/s"
                    KBytesReceived = Convert.ToInt32(Math.Round(NetReceived.NextValue / 1024, 0, MidpointRounding.AwayFromZero))
                    Me.StatusDown.Text = KBytesReceived & " kB/s"
                    Threading.Thread.Sleep(1000)
                Loop
    That code is working..
    However if try to use other speed meter I got different readings..
    See image.. my app is #1 in image..

    what could be the difference to my codes?
    Last edited by dr_aybyd; Dec 9th, 2010 at 01:16 AM.
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: PerformanceCounter question.

    Is it generally out by a factor of 8 by any chance, like 8 bits per byte maybe? "kbps" is kilobits per second, not kilobytes per second.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Re: PerformanceCounter question.

    Ahhh I see...
    But in where specific part of my codes should I modify to make mine like that?
    Should I change my ToInt32? Into Decimal? Or any other way...
    I tried String Format.

    Code:
    [String].Format("{0:n} kbps", pcNetReceived.NextValue / 1024.0)
    But only appears 0.00 kbps and do not change as I expected..
    Last edited by dr_aybyd; Dec 9th, 2010 at 09:09 AM.
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

  4. #4
    New Member
    Join Date
    Dec 2010
    Posts
    2

    Re: PerformanceCounter question.

    Quote Originally Posted by dr_aybyd View Post
    Ahh so the other is in kilobits and mine is kiloBytes..so that there are diff readings...
    What's the difference??

  5. #5
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: PerformanceCounter question.

    Quote Originally Posted by dr_aybyd View Post
    I have a function that will get the present upload and download rate of my current connection.

    It is working now here is my code used:

    Code:
     
            Dim NetSent As New System.Diagnostics.PerformanceCounter
            Dim NetReceived As New System.Diagnostics.PerformanceCounter

    What category & instance name are you using?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Re: PerformanceCounter question.

    Quote Originally Posted by nbrege View Post
    What category & instance name are you using?
    Code:
                With NetSent
                    .CategoryName = "Network Interface"
                    .CounterName = "Bytes Sent/sec"
                    .InstanceName = "WAN [PPP_SLIP] Interface"
                End With
    
                With NetReceived
                    .CategoryName = "Network Interface"
                    .CounterName = "Bytes Received/sec"
                     .InstanceName = "WAN [PPP_SLIP] Interface"
                End With
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: PerformanceCounter question.

    Quote Originally Posted by winterwinter View Post
    What's the difference??
    You should read the information that's already been provided before asking questions
    Quote Originally Posted by jmcilhinney View Post
    Is it generally out by a factor of 8 by any chance, like 8 bits per byte maybe? "kbps" is kilobits per second, not kilobytes per second.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Re: PerformanceCounter question.

    What should I use

    .NextValue
    or
    .RawValue
    If I use RawValue is that also in Bytes format?

    @jm
    its kilobits...
    its my mistake...not kilobytes..
    thanks...
    Last edited by dr_aybyd; Dec 9th, 2010 at 05:57 PM.
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

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