Exemplo n.º 1
0
 public override Task <double> CpuUsage()
 {
     return(Task.Run(() =>
     {
         return Math.Round(CpuCounter.NextValue());
     }));
 }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
 private static double CpuUsage()
 {
     if (CpuCounter == null)
     {
         CpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
     }
     return(Math.Round(CpuCounter.NextValue()));
 }
Exemplo n.º 4
0
        // Methods
        private void timerCpu_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!UserSettings.GlobalSettings.VisibilitySystemCpuUsage)
            {
                return;
            }

            try
            {
                CpuUsage = CpuCounter.GetSystemCpuUsageValue();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 5
0
 private static string ConstructCpuLabelText(CpuCounter counter)
 {
     return(counter.CpuUsage + "%");
 }
Exemplo n.º 6
0
 public FrameCounter()
 {
     _stopWatch  = new Stopwatch();
     _cpuCounter = new CpuCounter(this);
 }