Im currently developing something to track CPU usage but as soon as i started the thread that pulls the data from the CPU the screen went blank as if i started a fresh program.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Management.Instrumentation;
using System.Management;
using System.Collections.Specialized;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Thread cpuData;
public Form1()
{
cpuData = new Thread(new ThreadStart(cpuDataThread));
cpuData.Start();
}
public void cpuDataThread()
{
ulong i;
i = 0;
try
{
ManagementClass cpuDataClass = new ManagementClass("Win32_PerfFormattedData_PerfOS_Processor");
while (true)
{
ManagementObjectCollection cpuDataClassCollection = cpuDataClass.GetInstances();
foreach (ManagementObject obj in cpuDataClassCollection)
{
if (obj["Name"].ToString() == "_Total")
{
i = Convert.ToUInt64(obj["C1TransitionsPersec"]);
}
}
Thread.Sleep(100);
}
}
catch (ThreadAbortException tbe)
{
}
progressBar1.Maximum = 100;
progressBar1.Minimum = 1;
progressBar1.Value = (int)i;
}
}
}
This is just a program i wrote for personal usage but id like to get it working, the progress bar also does not work id like to get some help with that as well.