What should you do?

You work as the application developer at Domain.com.
You are developing a .NET Framework 2.0 Windows Service application named TestScannerSync that will be used to constantly monitor for a scanner to be connected to the computer.
The TestScannerSync class inherits its functionality from the ServiceBase class.
When you connect a scanner the service synchronizes its data with the data in a SQL Server database.
You decide to override the OnStop method in the TestScannerSync class and write code to close database connections.
You are required to identify a place in the code where you can open the connection to the database.
What should you do?

You work as the application developer at Domain.com.
You are developing a .NET Framework 2.0 Windows Service application named TestScannerSync that will be used to constantly monitor for a scanner to be connected to the computer.
The TestScannerSync class inherits its functionality from the ServiceBase class.
When you connect a scanner the service synchronizes its data with the data in a SQL Server database.
You decide to override the OnStop method in the TestScannerSync class and write code to close database connections.
You are required to identify a place in the code where you can open the connection to the database.
What should you do?

A.
The database connection is opened in the constructor of TestScannerSync class

B.
The database connection is opened in the OnContinue method of TestScannerSync class

C.
The database connection is opened in the OnStart method of the TestScannerSync class

D.
The database connection is opened in the OnPowerEvent method of the TestScannerSync class

Explanation:
The constructor for a service class derived from ServcieBase is called the first time you call Start on the service, the OnStart command-handling method is called immediately after the constructor executes.
Incorrect Answers:
A: The constructor is the incorrect choice as this is only called upon once and not again.
B: This method should not be used as this code will be executed when a Continue command is sent to a service in a paused state.
D: This method should not be considered as this method will execute when the computer’s power state has changed.



Leave a Reply 1

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


mr_tienvu

mr_tienvu

I have the same idea. C