public async Task <ResourceUsage> GetResourceUsageAsync() { var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); var ramCounter = new PerformanceCounter("Memory", "Available MBytes"); cpuCounter.NextValue(); ramCounter.NextValue(); await Task.Delay(_delay); var cpuUsage = cpuCounter.NextValue(); var ramUsage = ramCounter.NextValue(); return(ResourceUsage.Create(cpuUsage, ramUsage)); }
public async Task <ResourceUsage> GetResourceUsageAsync() { var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); var ramCounter = new PerformanceCounter("Memory", "Available MBytes"); if (!string.IsNullOrWhiteSpace(_machineName)) { cpuCounter.MachineName = _machineName; ramCounter.MachineName = _machineName; } cpuCounter.NextValue(); ramCounter.NextValue(); await Task.Delay(_delay); var cpuUsage = cpuCounter.NextValue(); var ramUsage = ramCounter.NextValue(); return(ResourceUsage.Create(cpuUsage, ramUsage)); }