Получить текущее использование ЦП, ОЗУ и жесткого диска в C #

Как получить использование ЦП, ОЗУ и жесткого диска в системе в коде C #?


person Sauron    schedule 10.08.2009    source источник


Ответы (3)


Пожалуйста, ищите ТАК; есть несколько похожих вопросов:

person Mitch Wheat    schedule 10.08.2009
comment
Как получить использование жесткого диска? - person Sauron; 10.08.2009
comment
Через класс счетчика производительности. Путем изменения категории. - person Aamir; 10.08.2009

Вот решение, которое выведет использование диска, общий процент использования диска во время опроса Timer99:

 using System;
 using System.Diagnostics;
 using System.Windows;

 namespace diskpercent
 {
     public partial class MainWindow : Window
     {
         DispatcherTimer Timer99 = new DispatcherTimer();
         public MainWindow()
         {
             InitializeComponent();
             Timer99.Tick += Timer99_Tick; // don't freeze the ui
             Timer99.Interval = new TimeSpan(0, 0, 0, 0, 1024);
             Timer99.IsEnabled = true;
         }
         public PerformanceCounter myCounter =
            new PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");
         public Int32 j = 0;
         public void Timer99_Tick(System.Object sender, System.EventArgs e)

         {
                 //Console.Clear();
             j = Convert.ToInt32(myCounter.NextValue());      
                 //Console.WriteLine(j);
             textblock1.Text = j.ToString();
         }
     }
 }

и вот список общих счетчиков производительности:

 PerformanceCounter("Processor", "% Processor Time", "_Total");
 PerformanceCounter("Processor", "% Privileged Time", "_Total");
 PerformanceCounter("Processor", "% Interrupt Time", "_Total");
 PerformanceCounter("Processor", "% DPC Time", "_Total");
 PerformanceCounter("Memory", "Available MBytes", null);
 PerformanceCounter("Memory", "Committed Bytes", null);
 PerformanceCounter("Memory", "Commit Limit", null);
 PerformanceCounter("Memory", "% Committed Bytes In Use", null);
 PerformanceCounter("Memory", "Pool Paged Bytes", null);
 PerformanceCounter("Memory", "Pool Nonpaged Bytes", null);
 PerformanceCounter("Memory", "Cache Bytes", null);
 PerformanceCounter("Paging File", "% Usage", "_Total");
 PerformanceCounter("PhysicalDisk", "Avg. Disk Queue Length", "_Total");
 PerformanceCounter("PhysicalDisk", "Disk Read Bytes/sec", "_Total");
 PerformanceCounter("PhysicalDisk", "Disk Write Bytes/sec", "_Total");
 PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Read", "_Total");
 PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Write", "_Total");
 PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");
 PerformanceCounter("Process", "Handle Count", "_Total");
 PerformanceCounter("Process", "Thread Count", "_Total");
 PerformanceCounter("System", "Context Switches/sec", null);
 PerformanceCounter("System", "System Calls/sec", null);
 PerformanceCounter("System", "Processor Queue Length", null);
person pollaris    schedule 25.01.2017

Диски

static void Main(string[] args)
{
var drives = DriveInfo.GetDrives();
foreach (DriveInfo info in drives)
{
      Console.WriteLine("Name: {0}\nSize: {1}\nDrive Format: {2}", info.Name, info.TotalSize, info.DriveFormat);
}
 Console.ReadLine();
}
person Fernandes    schedule 26.06.2018