Jump to content

C#.net NOOB help

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
Share on other sites

Link to post
Share on other sites

Sorry I'm really new to coding and software stuff, where and what does it do?

Link to comment
Share on other sites

Link to post
Share on other sites

Hm actually Console.WriteLine does do formatting like that, so that should be fine.

 

You never actually said what was wrong with the code?

Link to comment
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
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
Share on other sites

Link to post
Share on other sites

Thank you Mo5 you've fixed it, just a little odd as it worked on Jerry's  :huh:

Link to comment
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

×