Jump to content

HI guys I'm very new to coding and stuff and currently I'm learning to use C#.net in Microsoft visual studio from Barancules Codegasm.

So anyway I'm on his third video and I've followed exactly what he's done. This is to build a system monitor software by the way. For the love of the flying spaghetti monster i can't see what's wrong with this code! It says in the debug it's the line I've highlighted but i can't see anything wrong this is. At this stage all this software is doing is monitoring the cpu load in percentage. Thanks in advance.

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Diagnostics;using System.Threading; namespace Jarvis{    class Program    {        static void Main(string[] args)        {            //this will pull the cureent cpu load in percentage            PerformanceCounter perfcpucount = new PerformanceCounter();             //infinite while loop            while (true)            {                Thread.Sleep(1000);                Console.WriteLine("CPU Load: {0}", perfcpucount.NextValue());            }        }    }}
Edited by colonel_mortis
Code tags
Link to comment
https://linustechtips.com/topic/346732-cnet-noob-help/
Share on other sites

Link to post
Share on other sites

I run it, it crashes immediately. when i run the debug this is the message i get.

 

An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll
 
Additional information: Failed to initialize because CategoryName is missing.
Link to comment
https://linustechtips.com/topic/346732-cnet-noob-help/#findComment-4721036
Share on other sites

Link to post
Share on other sites

 

HI guys I'm very new to coding and stuff and currently I'm learning to use C#.net in Microsoft visual studio from Barancules Codegasm.

So anyway I'm on his third video and I've followed exactly what he's done. This is to build a system monitor software by the way. For the love of the flying spaghetti monster i can't see what's wrong with this code! It says in the debug it's the line I've highlighted but i can't see anything wrong this is. At this stage all this software is doing is monitoring the cpu load in percentage. Thanks in advance.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
 
namespace Jarvis
{
    class Program
    {
        static void Main(string[] args)
        {
            //this will pull the cureent cpu load in percentage
            PerformanceCounter perfcpucount = new PerformanceCounter();
 
            //infinite while loop
            while (true)
            {
                Thread.Sleep(1000);
                Console.WriteLine("CPU Load: {0}", perfcpucount.NextValue());
            }
        }
    }
}

 

You need to add parameters - PerformanceCounter perfCPUCount = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/346732-cnet-noob-help/#findComment-4721078
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×