我正在研究电荷平衡系统,因此我需要知道每台机器的费用.PerformanceCounter似乎要走了,但创建第一个需要38到60秒.然而,每个后续的新计数器或'NextValue'呼叫几乎是即时的.
这是我正在使用的代码:
[TestClass]
public class PerfMon
{
[TestMethod]
public void SimpleCreationTest()
{
Stopwatch Time = new Stopwatch();
Time.Start();
Debug.WriteLine("Time is : " + Time.ElapsedMilliseconds);
// Create
PerformanceCounter RAM = new PerformanceCounter("Memory", "Available MBytes");
Debug.WriteLine("Time is : " + Time.ElapsedMilliseconds + " => RAM created");
PerformanceCounter CPU = new PerformanceCounter("Processor", "% Processor Time", "_Total");
Debug.WriteLine("Time is : " + Time.ElapsedMilliseconds + " => CPU created");
PerformanceCounter GC = new PerformanceCounter(".NET CLR Memory", "% Time in GC", "_Global_");
Debug.WriteLine("Time is : " …Run Code Online (Sandbox Code Playgroud) c# performance load-balancing performancecounter shared-resource