What should you do?

You develop a service application named PollingService that periodically calls long-running procedures. These procedures are called from the DoWork method. You use the following service application code:
partial class PollingService : ServiceBase
{
bool blnExit = false;
public PollingService() {}
protected override void OnStart(string[] args)
{
do
{
DoWork();
} while (!blnExit);
}
protected override void OnStop()
{
blnExit = true;
}
private void DoWork() { …}
}
When you attempt to start the service, you receive the following error message: Could not start the PollingService service on the local computer. Error 1053: The service did not respond to the start or control request in a timely fashion. You need to modify the service application code so that the service starts properly. What should you do?

You develop a service application named PollingService that periodically calls long-running procedures. These procedures are called from the DoWork method. You use the following service application code:

partial class PollingService : ServiceBase
{
bool blnExit = false;
public PollingService() {}
protected override void OnStart(string[] args)
{
do
{
DoWork();
} while (!blnExit);
}
protected override void OnStop()
{
blnExit = true;
}
private void DoWork() { …}
}

When you attempt to start the service, you receive the following error message: Could not start the PollingService service on the local computer. Error 1053: The service did not respond to the start or control request in a timely fashion. You need to modify the service application code so that the service starts properly.

What should you do?

A.
Move the loop code into the constructor of the service class from the OnStart method.

B.
Drag a timer component onto the design surface of the service. Move the calls to the longrunning
procedure from the OnStart method into the Tick event procedure of the timer, set
the Enabled property of the timer to True, and call the Start method of the timer in the
OnStart method.

C.
Add a class-level System.Timers.Timer variable to the service class code. Move the call to
the DoWork method into the Elapsed event procedure of the timer, set the Enabled property
of the timer to True, and call the Start method of the timer in the OnStart method.

D.
Move the loop code from the OnStart method into the DoWork method.



Leave a Reply 2

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


Dan

Dan

ADMIN: I’m pretty sure this question doesn’t belong here.

Earnest

Earnest

Dan I agree with you.