Hardware/CPU/AMD0FCPU.cs
changeset 25 ff3e6edc7113
parent 24 09ab31bee6bd
child 26 0e01b63e1fdc
     1.1 --- a/Hardware/CPU/AMD0FCPU.cs	Wed Feb 03 20:35:10 2010 +0000
     1.2 +++ b/Hardware/CPU/AMD0FCPU.cs	Wed Feb 03 22:02:58 2010 +0000
     1.3 @@ -80,19 +80,29 @@
     1.4        // max two cores
     1.5        coreCount = coreCount > 2 ? 2 : coreCount;
     1.6  
     1.7 -      totalLoadCounter = new PerformanceCounter();
     1.8 -      totalLoadCounter.CategoryName = "Processor";
     1.9 -      totalLoadCounter.CounterName = "% Processor Time";
    1.10 -      totalLoadCounter.InstanceName = "_Total";
    1.11 +      try {
    1.12 +        totalLoadCounter = new PerformanceCounter();
    1.13 +        totalLoadCounter.CategoryName = "Processor";
    1.14 +        totalLoadCounter.CounterName = "% Processor Time";
    1.15 +        totalLoadCounter.InstanceName = "_Total";
    1.16 +        totalLoadCounter.NextValue();
    1.17 +      } catch (Exception) {
    1.18 +        totalLoadCounter = null;
    1.19 +      }
    1.20        totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
    1.21  
    1.22        coreLoadCounters = new PerformanceCounter[coreCount];
    1.23        coreLoads = new Sensor[coreCount];
    1.24        for (int i = 0; i < coreLoadCounters.Length; i++) {
    1.25 -        coreLoadCounters[i] = new PerformanceCounter();
    1.26 -        coreLoadCounters[i].CategoryName = "Processor";
    1.27 -        coreLoadCounters[i].CounterName = "% Processor Time";
    1.28 -        coreLoadCounters[i].InstanceName = i.ToString();
    1.29 +        try {
    1.30 +          coreLoadCounters[i] = new PerformanceCounter();
    1.31 +          coreLoadCounters[i].CategoryName = "Processor";
    1.32 +          coreLoadCounters[i].CounterName = "% Processor Time";
    1.33 +          coreLoadCounters[i].InstanceName = i.ToString();
    1.34 +          coreLoadCounters[i].NextValue();
    1.35 +        } catch (Exception) {
    1.36 +          coreLoadCounters[i] = null;
    1.37 +        }
    1.38          coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1,
    1.39            SensorType.Load, this);
    1.40        }        
    1.41 @@ -153,13 +163,16 @@
    1.42          }
    1.43        }
    1.44  
    1.45 -      totalLoad.Value = totalLoadCounter.NextValue();
    1.46 -      ActivateSensor(totalLoad);
    1.47 +      if (totalLoadCounter != null) {
    1.48 +        totalLoad.Value = totalLoadCounter.NextValue();
    1.49 +        ActivateSensor(totalLoad);
    1.50 +      }
    1.51  
    1.52 -      for (int i = 0; i < coreLoads.Length; i++) {
    1.53 -        coreLoads[i].Value = coreLoadCounters[i].NextValue();
    1.54 -        ActivateSensor(coreLoads[i]);
    1.55 -      }
    1.56 +      for (int i = 0; i < coreLoads.Length; i++)
    1.57 +        if (coreLoadCounters[i] != null) {
    1.58 +          coreLoads[i].Value = coreLoadCounters[i].NextValue();
    1.59 +          ActivateSensor(coreLoads[i]);
    1.60 +        }
    1.61      }
    1.62  
    1.63      private void ActivateSensor(Sensor sensor) {