예제 #1
0
 public CpuUsage(ProcessUsage processUsage = null, PerformanceCounter counter = null)
 {
     if (processUsage != null && counter != null)
     {
         SetPercentage(processUsage, counter);
     }
 }
예제 #2
0
        public void SetPercentage(ProcessUsage process)
        {
            double memory     = process.WorkingSet64;
            double percentage = (memory / SYSTEM_MEMORY) * 100;

            Percentage = percentage.ToString();
        }
예제 #3
0
 public MemoryUsage(ProcessUsage processUsage = null)
 {
     if (processUsage != null)
     {
         SetValues(processUsage);
     }
 }
예제 #4
0
        public bool TryCollectInfo(ProcessUsage processUsageInfo)
        {
            if (!PerformanceCounters.ContainsKey(processUsageInfo.Name))
            {
                PerformanceCounters.Add(processUsageInfo.Name, new PerformanceCounter("Process", "Working Set", processUsageInfo.Name, true));
            }

            try
            {
                var ram = PerformanceCounters[processUsageInfo.Name].NextValue();
                processUsageInfo.Ram = (ram / 1024 / 1024);

                return(true);
            }
            catch
            {
                PerformanceCounters[processUsageInfo.Name].Dispose();
                PerformanceCounters.Remove(processUsageInfo.Name);
            }

            return(false);
        }
예제 #5
0
        public bool TryCollectInfo(ProcessUsage processUsageInfo)
        {
            if (!PerformanceCounters.ContainsKey(processUsageInfo.Name))
            {
                PerformanceCounters.Add(processUsageInfo.Name, new PerformanceCounter("Process", "% Processor Time", processUsageInfo.Name, true));
            }

            try
            {
                var cpu = PerformanceCounters[processUsageInfo.Name].NextValue();
                processUsageInfo.Cpu = cpu / Environment.ProcessorCount;

                return(true);
            }
            catch
            {
                PerformanceCounters[processUsageInfo.Name].Dispose();
                PerformanceCounters.Remove(processUsageInfo.Name);
            }

            return(false);
        }
예제 #6
0
 private void SetPercentage(ProcessUsage processUsage, PerformanceCounter counter)
 {
     Percentage = Math.Round(counter.NextValue() / Environment.ProcessorCount, 2).ToString();
 }
예제 #7
0
 private void SetValues(ProcessUsage processUsage)
 {
     SetMB(processUsage);
     SetPercentage(processUsage);
 }
예제 #8
0
 public MemoryUsage Update(ProcessUsage processUsage)
 {
     SetValues(processUsage);
     return(this);
 }
예제 #9
0
 public void SetMB(ProcessUsage processUsage)
 {
     MB = (processUsage.WorkingSet64 / BYTE_TO_MEGABYTE_DIVIDER).ToString();
 }