0
這是代碼:性能計數器拋出拋出:SecurityException
private static void CreateCounter()
{
if (PerformanceCounterCategory.Exists("DemoCategory"))
PerformanceCounterCategory.Delete("DemoCategory");
CounterCreationDataCollection ccdArray = new CounterCreationDataCollection();
CounterCreationData ccd = new CounterCreationData();
ccd.CounterName = "RequestsPerSecond";
ccd.CounterType = PerformanceCounterType.NumberOfItems32;
ccd.CounterHelp = "Requests per second";
ccdArray.Add(ccd);
PerformanceCounterCategory.Create("DemoCategory", "Demo category",
PerformanceCounterCategoryType.SingleInstance, ccdArray);
Console.WriteLine("Press any key, to start use the counter");
}
很明顯:
PerformanceCounterCategory.Create("DemoCategory", "Demo category",
PerformanceCounterCategoryType.SingleInstance, ccdArray);
就是拋出異常的線。
我已閱讀約PerformanceCounterPermission
,我該怎麼辦?
修改您的應用程序的清單,使'requestedExecutionLevel'設置爲'requireAdministrator'。 –
@CodyGray已解決。謝謝;) –
不客氣。增加了一個完整的答案(現在我不再使用手機了!),以便您可以接受並解決問題。 –