Estoy escribiendo un programa que supervisa varios recursos de la computadora, como el uso de la CPU, etc. Quiero monitorear también el uso de la GPU (la carga de la GPU, no la temperatura).¿Cómo puedo leer la carga de la GPU?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using DannyGeneral;
namespace CpuUsage
{
public partial class Form1 : Form
{
private bool processEnded;
private Process[] processList;
private string timeStarted;
private string timeEnded;
private List<float> processValues;
private bool alreadyRun;
private DateTime dt;
private DateTime dt1;
private PerformanceCounter theCPUCounter;
private PerformanceCounter theMemCounter;
private PerformanceCounter specProcessCPUCounter;
private float cpuUsage;
private float memUsage;
private List<float> Values;
public Form1()
{
InitializeComponent();
processEnded = false;
processList = Process.GetProcesses();
for (int i = 0; i < processList.Count(); i++)
{
listView1.Items.Add(processList[i].ProcessName);
}
processValues = new List<float>();
alreadyRun = false;
dt = DateTime.Now;
Values = new List<float>();
theCPUCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
theMemCounter = new PerformanceCounter("Memory", "Available MBytes");
specProcessCPUCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);
Logger.Write("The Program Started At *** " + DateTime.Now.ToShortTimeString());
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
memUsage = theMemCounter.NextValue();
label1.Text = memUsage.ToString();
Logger.Write("Memory Usage " + memUsage.ToString());
cpuUsage = this.theCPUCounter.NextValue();
label2.Text = cpuUsage.ToString();
Logger.Write("Cpu Usage " + this.cpuUsage.ToString());
Values.Add(cpuUsage);
isProcessRunning();
if (alreadyRun == true)
{
processValues.Add(cpuUsage);
}
}
Para futuras preguntas, considere proporcionar una muestra más pequeña con solo el código relevante. Su actual tiene demasiadas cosas relacionadas con la interfaz de usuario donde 'Console.Write simple (" CPU usage: {0} ", nuevo PerformanceCounter (" Processor ","% Processor Time "," _Total "); .NextValue()) 'sería suficiente. –