성능 데이터를 표시하는 폼을 수행 중이며 프로세서와 메모리에 대한 몇 가지 정보를 표시하는 몇 가지 성능 카운터가 있습니다. 첫 번째 결과는 항상 "0"이므로 다음 값을 할당하기 전에 절전 스레드를 수행하고 있습니다. 이렇게함으로써 문제는 실제로 프로그램을 느리게 만드는 것입니다.PerformanceCounters를 코딩하는 가장 좋은 방법
심지어 창을 이동하는 속도가 느리며 기본적으로 다른 두 번째 실행중인 스레드 잠자기 이벤트로 인해 내기. 타이머를 항상 1 초 간격으로 활성화하도록 설정 했으므로 "실시간"정보를 표시해야합니다.
private PerformanceCounter pcProcess; //Process
private PerformanceCounter pcMemory; //Memory
private void tmrProcess_Tick(System.Object sender, System.EventArgs e)
{
pcProcess = new PerformanceCounter(); //New Performance Counter Object
pcProcess.CategoryName = "Processor"; //Specify Process Counter
pcProcess.CounterName = "Interrupts/sec";
pcProcess.InstanceName = "_Total";
pcProcess.NextValue();
System.Threading.Thread.Sleep(1000);
cpInt.Text = pcProcess.NextValue().ToString(); //Display
pcProcess.CounterName = "% Processor Time";
pcProcess.InstanceName = "_Total";
pcProcess.NextValue();
System.Threading.Thread.Sleep(1000);
cpPower.Text = pcProcess.NextValue().ToString() + "%"; //Display
}
private void tmrMemory_Tick(System.Object sender, System.EventArgs e)
{
pcMemory = new PerformanceCounter();
pcMemory.CategoryName = "Memory";
//This counter gives a general idea of how many times information being requested is not where the application (and VMM) expects it to be
pcMemory.CounterName = "Available MBytes";
avlMem.Text = pcMemory.NextValue().ToString() + " Mb";
pcMemory.CounterName = "Page Faults/sec";
pcMemory.NextValue();
System.Threading.Thread.Sleep(1000);
pgFaults.Text = pcMemory.NextValue().ToString();
}
내가 performancecounter 두 번 전화를해야할까요? 그래서 this.pcMemory = new PerformanceCounter this.pcProcess = new PerformanceCounter(); – user263029
@ user263029 예, 모니터링 할 각 카운터에 대해 하나의 인스턴스가 있어야합니다. – ken2k