91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C# 獲取內存和CPU信息的源碼

發布時間:2020-06-24 19:49:01 來源:網絡 閱讀:435 作者:rhododend 欄目:編程語言

將內容過程中經常用的一些內容段備份一下,如下資料是關于C# 獲取內存和CPU信息的的內容,希望能對大伙有一些用。

using System.Collections;
using System.Collections.Generic;
using System.Management;
using System.Text;

namespace MergeSystem.Indexus.WinServiceCommon.SystemManagement
{
    public class Cpu
    {
        public static void LogCpuData()
        {
            System.Collections.ArrayList result = new System.Collections.ArrayList();
            ManagementScope mgmtScope = new ManagementScope(@"/. ootcimv2");
            mgmtScope.Connect();

            ManagementPath mp = new ManagementPath("Win32_Processor");
            ManagementClass mc = new ManagementClass(mgmtScope, mp, null);
            ManagementObjectCollection procs = mc.GetInstances();

            foreach (ManagementObject mo in procs)
            {
                foreach (PropertyData pd in mo.Properties)
                {
                    switch (pd.Name)
                    {
                        case "DeviceID":
                        case "Name":
                        case "LoadPercentage":
                            Console.WriteLine(@"Name: {0}; Value: {1}", pd.Name, pd.Value == null ? string.Empty : pd.Value.ToString().Trim());
                            Handler.LogHandler.Info(string.Format(@"Name: {0}; Value: {1}", pd.Name, pd.Value == null ? string.Empty : pd.Value.ToString().Trim()));
                            Handler.LogHandler.MemoryFatalException(string.Format(@"Name: {0}; Value: {1}", pd.Name, pd.Value == null ? string.Empty : pd.Value.ToString().Trim()));

                            break;
                    }
                }
                Console.WriteLine(@" --- ");
                Handler.LogHandler.Info(@" --- ");
            }
        }
    }
}

獲取內存信息

using System;
using System.Collections;
using System.Collections.Generic;
using System.Management;
using System.Text;

namespace MergeSystem.Indexus.WinServiceCommon.SystemManagement
{
    public class Memory
    {

        public static void LogMemoryData()
        {
            ManagementScope mgmtScope = new ManagementScope(@"/. ootcimv2");
            mgmtScope.Connect();

            ManagementPath mp = new ManagementPath("Win32_OperatingSystem");
            ManagementClass mc = new ManagementClass(mgmtScope, mp, null);
            ManagementObjectCollection procs = mc.GetInstances();

            foreach (ManagementObject mo in procs)
            {
                foreach (PropertyData pd in mo.Properties)
                {
                    switch (pd.Name)
                    {
                        case "BuildNumber":
                        case "BuildType":
                        case "Caption":
                        case "CountryCode":
                        case "CSDVersion":
                        case "CSName":
                        case "CurrentTimeZone":
                        case "FreePhysicalMemory":
                        case "FreeSpaceInPagingFiles":
                        case "FreeVirtualMemory":
                        case "LastBootUpTime":
                        case "MaxNumberOfProcesses":
                        case "MaxProcessMemorySize":
                        case "NumberOfProcesses":
                        case "NumberOfUsers":
                        case "Organization":
                        case "OSLanguage":
                        case "RegisteredUser":
                        case "SerialNumber":
                        case "ServicePackMajorVersion":
                        case "ServicePackMinorVersion":
                        case "SizeStoredInPagingFiles":
                        case "SystemDevice":
                        case "SystemDirectory":
                        case "SystemDrive":
                        case "TotalVirtualMemorySize":
                        case "TotalVisibleMemorySize":
                        case "Version":
                        case "WindowsDirectory":
                            Console.WriteLine(@"Name: {0}; Value: {1}", pd.Name, pd.Value == null ? string.Empty : pd.Value.ToString().Trim());
                            Handler.LogHandler.Info(string.Format(@"Name: {0}; Value: {1}", pd.Name, pd.Value == null ? string.Empty : pd.Value.ToString().Trim()));
                            Handler.LogHandler.MemoryFatalException(string.Format(@"Name: {0}; Value: {1}", pd.Name, pd.Value == null ? string.Empty : pd.Value.ToString().Trim()));
                            break;
                    }                    
                }
                Console.WriteLine(@" --- ");
                Handler.LogHandler.Info(@" --- ");
            }

        }
    }
}
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

南丰县| 汨罗市| 石林| 新邵县| 公主岭市| 富源县| 中卫市| 钦州市| 西城区| 平遥县| 茌平县| 九台市| 高要市| 定日县| 祁门县| 乌苏市| 万全县| 东乡县| 灌阳县| 洛隆县| 泾川县| 平山县| 长岭县| 建水县| 广汉市| 奉节县| 上蔡县| 鄄城县| 凌海市| 桦甸市| 兰西县| 阿尔山市| 凤阳县| 汽车| 苏尼特左旗| 达日县| 孝昌县| 应用必备| 台中县| 石首市| 馆陶县|