Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to ask the prozessorstate

Status
Not open for further replies.

Kostarsus

Programmer
Nov 30, 2000
86
DE
Hi,

I want to write a program, that checks the cpu use in advance, before the realy pogram starts.
So my question: How can I get the cpu use by a program?
An example would be nice, but if you post the namespaces and Objects, which I have to use, I can read in the documentation.

cu Kostarsus
 
Here is a thing I wrote earlier for one of my programs.. Hope this helps
Code:
public class ProcessorUsage
	{
		public static CounterSample poll1 = new CounterSample();
		public static CounterSample poll2 = new CounterSample();
		public static PerformanceCounter procPolling = new PerformanceCounter();
		public static void ProcThread() 
		{
			procPolling.CategoryName = "Processor";
			procPolling.CounterName = "% Processor Time";
			procPolling.InstanceName = "_Total";
			int i = 0;
			do 
			
			{
				poll1 = procPolling.NextSample();
				Thread.Sleep(300);
				poll2 = procPolling.NextSample();
				Form1.form1.progressBar1.Value = Convert.ToInt32(CounterSample.Calculate(poll1,poll2));
		        }
	while (i == 0);
        }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top