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 7746671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:20:18+00:00 2026-06-01T10:20:18+00:00

When I create and use performance counters like this: private readonly PerformanceCounter _cpuPerformanceCounter; public

  • 0

When I create and use performance counters like this:

private readonly PerformanceCounter _cpuPerformanceCounter;
public ProcessViewModel(Process process)
        {

             _cpuPerformanceCounter = new PerformanceCounter("Process", "% Processor Time", process.ProcessName, true);
        }

public void Update()
        {
            CPU = (int)_cpuPerformanceCounter.NextValue() / Environment.ProcessorCount; // Exception
        }

… I get an exception Instance ‘Name of instance’ does not exist in the specified Category and don’t understand why.

P.S. Code

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.net>
    <settings>
      <performanceCounters enabled="true"/>
    </settings>
  </system.net>
</configuration>

… included in App.config.

  • 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-01T10:20:20+00:00Added an answer on June 1, 2026 at 10:20 am

    Adding on to previous posts, I have seen processes being formatted like <ProcessName>_<ProcessId> – depending on the OS you are running your app on (Win XP, Win Vista, Win 7, Win 2003 or 2008 Server). In order to have a reliable way to identify your process name for obtaining other performance counters down the road, a function could look like this:

        private string ObtainProcessName()
        {
            string baseProcessName;
            string processName = null;
            int processId;
            bool notFound = true;
            int processOptionsChecked = 0;
            int maxNrOfParallelProcesses = 3 + 1;
    
            try
            {
                baseProcessName = Process.GetCurrentProcess().ProcessName;
            }
            catch (Exception exception)
            {
                return null;
            }
    
            try
            {
                processId = Process.GetCurrentProcess().Id;
            }
            catch (Exception exception)
            {
                return null;
            }
    
            while (notFound)
            {
                processName = baseProcessName;
                if (processOptionsChecked > maxNrOfParallelProcesses)
                {
                    break;
                }
    
                if (1 == processOptionsChecked)
                {
                    processName = string.Format("{0}_{1}", baseProcessName, processId);
                }
                else if (processOptionsChecked > 1)
                {
                    processName = string.Format("{0}#{1}", baseProcessName, processOptionsChecked - 1);
                }
    
                try
                {
                    PerformanceCounter counter = new PerformanceCounter("Process", "ID Process", processName);
                    if (processId == (int)counter.NextValue())
                    {
                        notFound = !true;
                    }
                }
                catch (Exception)
                {
                }
                processOptionsChecked++;
            }
            return processName;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create/use a system-wide independent universal 'counter object' that can be
This is a design question: when do I need to create/use a static method
I would like to use create a rails route for a user's open id.
when I create Animal x=new Dog(); and I want to use Dog functions, I
Possible Duplicate: Do the amount of namespaces affect performance? When you create a new
Suppose I have simple class like: class MyClass { private $_prop; public function getProp()
When I create performance counters in Windows Vista, I see that there is a
I have a somewhat special use case, where I'd like to create a method
I am trying to use the Windows performance counters to get the virtual bytes
Are there any disadvantages or performance slowdowns related to the use of expressions like

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.