Нужны ли мне повышенные права в Windows для доступа к PerformanceCounterC#

Место общения программистов C#
Ответить
Anonymous
 Нужны ли мне повышенные права в Windows для доступа к PerformanceCounter

Сообщение Anonymous »

У меня есть эта строка кода, это внезапно вызывает проблемы. < /p>

Код: Выделить всё

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()
Я сделал обходной путь WMI, но мне все еще интересно, почему это внезапно является проблемой.

Подробнее здесь: https://stackoverflow.com/questions/797 ... ncecounter
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»