public override Task <double> CpuUsage() { return(Task.Run(() => { return Math.Round(CpuCounter.NextValue()); })); }
/// <summary> /// Releases all used resouces by the <see cref="FusionProcess"/> instance. /// </summary> public void Dispose() { isAutoRestartEnabled = false; if (process?.HasExited == false) { try { process?.Kill(); } catch (Exception ex) when(ex is Win32Exception || ex is InvalidOperationException) { } try { process?.WaitForExit((int)defaultProcessTimeout.TotalMilliseconds); } catch (Exception ex) when(ex is Win32Exception || ex is SystemException) { } } CpuCounter?.Dispose(); CpuCounter = null; MemoryCounter?.Dispose(); MemoryCounter = null; process?.Dispose(); process = null; }
private static double CpuUsage() { if (CpuCounter == null) { CpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); } return(Math.Round(CpuCounter.NextValue())); }
// Methods private void timerCpu_Elapsed(object sender, ElapsedEventArgs e) { if (!UserSettings.GlobalSettings.VisibilitySystemCpuUsage) { return; } try { CpuUsage = CpuCounter.GetSystemCpuUsageValue(); } catch (Exception ex) { Console.WriteLine(ex); } }
private static string ConstructCpuLabelText(CpuCounter counter) { return(counter.CpuUsage + "%"); }
public FrameCounter() { _stopWatch = new Stopwatch(); _cpuCounter = new CpuCounter(this); }