You have added the following class to the Windows service application…

You have been given the task of developing a Windows service application that regularly monitors other Windows services on the same computer.
This Windows service application must also log any abnormal file system activity. You have added the following class to the Windows service application:
public class EnumerateService : ServiceBase {
public static EnumerateService () {
this.ServiceName = “Enumerate Service”;
this.CanStop = true;
}

You have been given the task of developing a Windows service application that regularly monitors other Windows services on the same computer.
This Windows service application must also log any abnormal file system activity. You have added the following class to the Windows service application:
public class EnumerateService : ServiceBase {
public static EnumerateService () {
this.ServiceName = “Enumerate Service”;
this.CanStop = true;
}

What should you do?

A.
Override the OnBoot method instead of the OnStart method.

B.
Replace the Main method code with the following code:
EnumerateService service = new EnumerateService();
service.Run();

C.
Override the OnLoad method instead of the OnStart method.

D.
Replace the Main method code with the following code:
EnumerateService service = new EnumerateService();
Run(service);

Explanation:
For a Windows service to run in an application process, you have to invoke the Run method on the ServiceBase class. The Run method is overloaded to accept either a single ServiceBase object or an array of ServiceBase objects. The OnStart method code is executed when a Windows service is either manually started or when the system is booted if the Startup type is set to Automatic. The OnStop method code is executed when a Windows service is either manually stopped or when the system is shut down. The Main method is the first point of execution when running any windows application (.exe).
Incorrect Answers:
A C: You should not override the OnBoot or OnLoad method because there are no such methods in the ServiceBase class.
B: For a Windows service to run in an application process, you have to invoke the Run method on the ServiceBase class. The Run method is overloaded to accept either a single ServiceBase object or an array of ServiceBase objects. This code will not compile because the Run method is a class member and does not take zero arguments.



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Lisa

Lisa

What is the question?

mr_tienvu

mr_tienvu

I choose