当前位置: 首页 > 编程语言 > C#

获取当前CPU、RAM和磁盘驱动器使用情况分享

时间:2023-04-10 19:19:36 C#

inC#在C#中获取当前CPU、RAM和磁盘驱动器使用情况如何在C#代码中获取系统的CPU、RAM和磁盘驱动器使用情况?请搜索;有几个类似的问题:这是一个解决方案,将输出磁盘使用情况,轮询Timer99时使用的总磁盘百分比:usingSystem;使用系统诊断;使用System.Windows;namespacediskpercent{publicpartialclassMainWindow:Window{DispatcherTimerTimer99=newDispatcherTimer();publicMainWindow(){InitializeComponent();Timer99.Tick+=Timer99_Tick;//不要冻结uiTimer99.Interval=newTimeSpan(0,0,0,0,1024);Timer99.IsEnabled=真;}publicPerformanceCountermyCounter=newPerformanceCounter("PhysicalDisk","%DiskTime","_Total");公共Int32j=0;publicvoidTimer99_Tick(System.Objectsender,System.EventArgse){//Console.Clear();j=Convert.ToInt32(myCounter.NextValue());//控制台.WriteLine(j);textblock1.Text=j.ToString();}}}以下是常见性能计数器的列表:PerformanceCounter("Processor","%ProcessorTime","_Total");PerformanceCounter("处理器","%特权时间","_Total");性能计数器("处理器","%中断时间","_Total");PerformanceCounter("处理器","%DPC时间","_Total");PerformanceCounter("内存","可用MBytes",null);PerformanceCounter("内存","提交字节数",null);PerformanceCounter("内存","提交限制",null);PerformanceCounter("Memory","%CommittedBytesInUse",null);PerformanceCounter("Memory","PoolPagedBytes",null);PerformanceCounter("Memory","PoolNonpagedBytes",null);PerformanceCounter("内存","缓存字节数",null);PerformanceCounter("分页文件","%Usage","_Total");PerformanceCounter("PhysicalDisk","平均磁盘队列长度","_Total");PerformanceCounter("PhysicalDisk","磁盘读取字节数/秒","_Total");PerformanceCounter("PhysicalDisk","磁盘写入字节数/秒","_Total");PerformanceCounter("PhysicalDisk","Avg.Disksec/Read","_Total");PerformanceCounter("PhysicalDisk","Avg.Disksec/Write","_Total");PerformanceCounter("PhysicalDisk","%DiskTime","_Total");PerformanceCounter("进程","处理数","_Total");PerformanceCounter("进程","线程数","_Total");PerformanceCounter("系统","上下文切换/秒",null);PerformanceCounter("系统","系统调用/秒",null);PerformanceCounter("系统","处理器队列长度",null);驱动以上就是C#学习教程:GetthecurrentCPU,RAManddiskdriveusageinC#分享的所有内容,如果对你有用,需要进一步了解C#学习教程,希望大家多加关注—staticvoidMain(string[]args){vardrives=DriveInfo.GetDrives();foreach(驱动器中的DriveInfo信息){Console.WriteLine("Name:{0}nSize:{1}nDriveFormat:{2}",info.Name,info.TotalSize,info.DriveFormat);}控制台.ReadLine();}本文来自网络收藏,不代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: