Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8617295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:49:15+00:00 2026-06-12T05:49:15+00:00

I have this piece of code : Where I create my Performance Counter. It

  • 0

I have this piece of code :
Where I create my Performance Counter. It executes ok, if not exists it creates the performance counter as well, but I can’t find this performance counter, when I use perfmon.

What is happening?

 const string _categoryName = "MyPerformanceCounter";
    if (!PerformanceCounterCategory.Exists(_categoryName))
    {
        CounterCreationDataCollection counters = new CounterCreationDataCollection();

        CounterCreationData ccdWorkingThreads = new CounterCreationData();
        ccdWorkingThreads.CounterName = "# working threads";
        ccdWorkingThreads.CounterHelp = "Total number of operations executed";
        ccdWorkingThreads.CounterType = PerformanceCounterType.NumberOfItems32;
        counters.Add(ccdWorkingThreads);

        // create new category with the counters above
        PerformanceCounterCategory.Create(_categoryName,
                "Performance counters of my app",
                PerformanceCounterCategoryType.SingleInstance,
                counters);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:49:17+00:00Added an answer on June 12, 2026 at 5:49 am

    The reason for not receiving any exceptions is try-catch block is missing. If you add your statements in try and catch block like this

            try
            {                
                const string _categoryName = "MyPerformanceCounter";
                if (!PerformanceCounterCategory.Exists(_categoryName))
                {
                    CounterCreationDataCollection counters = 
                    new CounterCreationDataCollection();
    
                    CounterCreationData ccdWorkingThreads = new CounterCreationData();
                    ccdWorkingThreads.CounterName = "# working threads";
                    ccdWorkingThreads.CounterHelp = "Total number of operations executed";
                    ccdWorkingThreads.CounterType = PerformanceCounterType.NumberOfItems32;
                    counters.Add(ccdWorkingThreads);
    
                    // create new category with the counters above
                    PerformanceCounterCategory.Create(_categoryName,
                            "Performance counters of my app",
                            PerformanceCounterCategoryType.SingleInstance,
                            counters);
                }                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString()); //Do necessary action
            }   
    

    Then it will capture the exceptions.If you see exception like “Requested registry access is not allowed.” then you require administrative rights to do the stuff. To confirm this Run the Visual Studio with Administrative rights and execute the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code for my images, so the opacity can lower
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code which is running perfectly on localhost but throws
At this time, I have this piece of code for my employee class. But
I feel stupid asking this question, but I can not find a clear answer
I am using this piece of code to read from file but have an
I have this piece of code in a function. I want to print the
I have this piece of code: public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener) {
I have this piece of code: @Entity @Table(name = MOVERS) public class MOVers implements
I have this piece of code, <div id=event style=display:none;> <!-- initially hidden --> <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.