Domain.com is currently using a performance counter named HitCounter.
You are required to increment each time a user accesses the UI classes within the application.
To do this, you start by creating performance counters using the following code:
GRAPHICS – is not required for reply!
You have to adjust the HitCounter performance counter when a hit occurs.
What should you do?
A.
Use the following code:
PerformanceCounter hitCounter = new PerformanceCounter (“ApplicationPerformance’, “HitCounter”);
hitCounter.ReadOnly = false;
hitCounter.Increment ();
B.
Use the following code:
PerformanceCounter hitCounter = new PerformanceCounter (“ApplicationPerformance’, “HitCounter”);
hitCounter.Increment ();
C.
Use the following code:
PerformanceCounter hitCounter = new PerformanceCounter (“ApplicationPerformance’, “HitCounter”);
hitCounter ++;
D.
Use the following code:
PerformanceCounter hitCounter = new PerformanceCounter (“ApplicationPerformance’, “HitCounter”);
hitCounter.ReadOnly = false;
hitCounter ++;
Explanation:
This code creates a new PerformanceCounter object that references the ApplicationPerformance category and the HitCounterperformance counter. By default, a performance counter is read-only, so this code sets the ReadOnly property to False. Then, the Increment method is called to increase the counter by one. The PerformanceCounter class also provides an IncrementBy method, which increments the performance counter by the value specified in a provided argument.
Incorrect Answers:
B: You should not use the code fragments that fail to set the ReadOnly property to False because by default, all performance counter objects are read-only. C, D: You should not use the code fragments that use the ++ operator to increment the PerformanceCounter object because this will cause a compile-time error.
I agree with the answer. A