You have created a Windows service application for the purpose of monitoring the number of active
service requests running on Domain.com’s server.
You want to configure this Windows service application to produce a report every ten minutes.
You start by placing the reporting logic in the GenerateReport method of this Windows service.
You want to create a Timer object that invokes this method every ten minutes.
What should you do?
A.
Use the following code:
Timer tmrReport = new Timer(new TimerCallback (GenerateReport), null, 600000, 0);
B.
Use the following code:
Timer tmrReport = new Timer(new TimerCallback (GenerateReport), null, 10, 0);
C.
Use the following code:
Timer tmrReport = new Timer(new TimerCallback (GenerateReport), null, 0, 600000);
D.
Use the following code:
Timer tmrReport = new Timer(new TimerCallback (GenerateReport), null, 0, 10);
Explanation:
This code creates a Timer object named tmrReport that will invoke the GnerateReport every ten minutes. The first argument of the Timer constructor is a TimerCallback delegate that points to the method to be invoked. The second argument is the object that will be sent to the callback method. The third and fourth arguments are integers that specify delay and interval in milliseconds, respectively. Because the interval is in milliseconds, the following conversion must be made:
10 minutes = 10 * 60 seconds = 600 * 1000 milliseconds = 600,000 milliseconds Therefore, the delay is set to 0, and the interval is set to 600,000 milliseconds.
Incorrect Answers:
A: This option is incorrect because the delay and the interval arguments are reversed. If you use this option, then the tmrReport will invoke the GnerateReport method only once in ten minutes.
B: This option is incorrect because the delay and the interval arguments are reversed. Also, the interval argument is incorrectly specified. It should be specified in milliseconds.
D:
The interval argument is incorrectly specified. It should be specified in milliseconds, not minutes. This code would set the interval to ten milliseconds instead of ten minutes.
Correct answer is C