From cbc65ee83fda22c050ba4a03d020de8388983e61 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Jun 2012 16:35:00 +0200 Subject: [PATCH] fix profiler startup exception if performance counters are broken --- .../Data/PerformanceCounterDescriptor.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/AddIns/Analysis/Profiler/Controller/Data/PerformanceCounterDescriptor.cs b/src/AddIns/Analysis/Profiler/Controller/Data/PerformanceCounterDescriptor.cs index 51b324d772..a4589b464d 100644 --- a/src/AddIns/Analysis/Profiler/Controller/Data/PerformanceCounterDescriptor.cs +++ b/src/AddIns/Analysis/Profiler/Controller/Data/PerformanceCounterDescriptor.cs @@ -139,9 +139,21 @@ namespace ICSharpCode.Profiler.Controller.Data /// public void Collect(string instanceName) { - if (counter == null && Instance != null) - counter = new PerformanceCounter(Category, Name, instanceName ?? Instance, Computer); - + try { + if (counter == null && Instance != null) + counter = new PerformanceCounter(Category, Name, instanceName ?? Instance, Computer); + // These exceptions happen when something is wrong with the system settings or the perfmon service is not started. + // We will ignore performance counters in those cases. + } catch (Win32Exception) { + // Win32Exception (0x80004005): The service cannot be started, either because it is disabled + // or because it has no enabled devices associated with it + // see http://community.sharpdevelop.net/forums/p/10709/29534.aspx#29534 + return; + } catch (InvalidOperationException) { + // InvalidOperationException: Cannot load Counter Name data because an invalid index '' was read from the registry. + // see http://community.sharpdevelop.net/forums/p/14180/37895.aspx#37895 and SD-1819 + return; + } try { this.Values.Add(counter.NextValue()); #if DEBUG