What should you do?

You have recently created a Windows service application and need to define a Windows service class.
What should you do?

You have recently created a Windows service application and need to define a Windows service class.
What should you do?

A.
Use the following code:
public class TestService : System.ServiceProcess.WindowsService {
//Implementation details
}

B.
Use the following code:
public class TestService : System.ServiceProcess.IWindowsService {
//Implementation details
}

C.
Use the following code:
public class TestService : System.ServiceProcess.ServiceBase {
//Implementation details
}

D.
Use the following code:
public class TestService : System.ServiceProcess.IService {
//Implementation details
}

Explanation:
The ServiceBase class contains event methods, such as OnStart, OnStop, and Run, for controlling Windows service classes. 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). For a Windows service to run in an application process, you must 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.
Incorrect Answers:
A, B, D: You should not use either of the code fragments from the WindowsService class or implement the IService and IWindowsService interfaces because no such class or interfaces exist in the System.ServiceProcess namespace.



Leave a Reply 0

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