將內(nèi)容過(guò)程中經(jīng)常用的一些內(nèi)容段備份一下,如下資料是關(guān)于C# 獲取內(nèi)存和CPU信息的的內(nèi)容,希望能對(duì)大伙有一些用。
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)金水,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):13518219792using 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(@" --- ");
}
}
}
}
獲取內(nèi)存信息
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(@" --- ");
}
}
}
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。