Код: Выделить всё
private static readonly PerformanceCounter _cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
< /code>
работает как пользователь службы Windows, и вдруг я получаю эту ошибку, ранее она только что сработала. < /p>
2025-08-06 18:39:32.7577 | FATAL | SGRE.EDA.Services.HHRDR.HHRDRService | | UnhandledException caught, Runtime terminating | The type initializer for 'SGRE.EDA.Crosscutting.Utilities.ResourceMonitor' threw an exception.
at SGRE.EDA.Crosscutting.Utilities.ResourceMonitor.GetCurrentCpuUsage()
at SGRE.EDA.Services.HHRDR.HHRDRService.b__19_0(Object _)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
Access to the registry key 'Global' is denied.
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object defaultValue, Boolean doNotExpand, Boolean checkSecurity)
at Microsoft.Win32.RegistryKey.GetValue(String name)
at System.Diagnostics.PerformanceMonitor.GetData(String item)
at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item)
at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
at System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists)
at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
at System.Diagnostics.PerformanceCounter.InitializeImpl()
at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName)
at SGRE.EDA.Crosscutting.Utilities.ResourceMonitor..cctor()
Подробнее здесь: https://stackoverflow.com/questions/797 ... ncecounter