Results 1 to 4 of 4

Thread: Performance counter error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Performance counter error

    Hello all,

    I have this code sample from a book I'm reading which looks to be incorrect:

    Code:
    Imports System.Diagnostics
    
    Sub Main
            Dim pc As New PerformanceCounter("PerfApp", "Clicks", False) 'excepiton here
            pc.Increment()
            counterLabel.Content = pc.NextValue().ToString()
    End Sub
    There excepion message I get is: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.

    I looked for a property to see if I can set it but couldn't find one. Anyone know how I can correct this error?

    Thanks,

    Strick

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

    Re: Performance counter error

    30 seconds in the documentation and you'd have had your answer. Have you read the documentation for the PerformanceCounter constructor you're using? Do you know what the parameters mean?
    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
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: Performance counter error

    Hello,

    Thanks for your response. Yes I know what they mean and still cannot get it to work (spent about an hour trying to get it to work and surfing the net for answers) which is why I turned to the forum as a last resort.

    This statement is word for word from a book, so I'm expecting it to work, but it doesn't. I've tried flipping it to true, but I get a "category does not exist" exeption. Since the book says it should be false, I'm trying to get it to work based on how I'm recieving it.

    Thanks,

    Strick

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

    Re: Performance counter error

    I would recommend that you provide all the relevant information up front. Your first post says you were passing False to the 'readOnly' parameter and the error message you quoted says that the counter needed to be created read-only, so the obvious solution to that is to pass True to that parameter. If you'd already tried that then that would qualify as relevant information.
    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

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