我正在尝试从 ASP.NET MVC 应用程序(在 Windows 8 x64 PC 上使用 VS 2012)添加性能计数器,但我遇到的问题是,如果我检查类别是否存在或添加新的性能计数器类别,计算机会挂起
我的代码是:
namespace TestMvcCounter
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
if (!PerformanceCounterCategory.Exists("MY_TEST"))
{
CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
ccdc.Add(new CounterCreationData() { CounterName = "# loops", CounterType = PerformanceCounterType.RateOfCountsPerSecond32 });
PerformanceCounterCategory.Create("MY_TEST", "Test performance counter", PerformanceCounterCategoryType.MultiInstance, ccdc);
}
}
}
}
当代码到达这一行时
!PerformanceCounterCategory.Exists("MY_TEST")
系统挂起,没有任何异常或超时
你知道可能是什么原因导致这个问题吗?