第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲得C#中的CPU使用量?

如何獲得C#中的CPU使用量?

C#
慕標(biāo)琳琳 2019-06-28 16:35:52
如何獲得C#中的CPU使用量?我希望得到C#中應(yīng)用程序的總CPU使用量。我已經(jīng)找到了很多方法來深入了解進程的屬性,但是我只想要進程的CPU使用情況,以及像TaskManager中那樣的CPU總量。
查看完整描述

3 回答

?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

比所要求的稍多一點,但是我使用額外的計時器代碼來跟蹤和警告CPU使用率在持續(xù)1分鐘或更長時間內(nèi)是否達到90%或更高。

public class Form1{

    int totalHits = 0;

    public object getCPUCounter()
    {

        PerformanceCounter cpuCounter = new PerformanceCounter();
        cpuCounter.CategoryName = "Processor";
        cpuCounter.CounterName = "% Processor Time";
        cpuCounter.InstanceName = "_Total";

                     // will always start at 0
        dynamic firstValue = cpuCounter.NextValue();
        System.Threading.Thread.Sleep(1000);
                    // now matches task manager reading
        dynamic secondValue = cpuCounter.NextValue();

        return secondValue;

    }


    private void Timer1_Tick(Object sender, EventArgs e)
    {
        int cpuPercent = getCPUCounter();
        if (cpuPercent >= 90)
        {
            totalHits = totalHits + 1;
            if (totalHits == 60)
            {
                Interaction.MsgBox("ALERT 90% usage for 1 minute");
                totalHits = 0;
            }                        
        }
        else
        {
            totalHits = 0;
        }
        Label1.Text = cpuPercent + " % CPU";
        Label2.Text = getRAMCounter() + " RAM Free";
        Label3.Text = totalHits + " seconds over 20% usage";
    }}


查看完整回答
反對 回復(fù) 2019-06-28
  • 3 回答
  • 0 關(guān)注
  • 860 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號