.NET 2.0 and Windows Service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The following error occurs on trying to start a Windows Service that is based
on a C# application I am writing:

[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely
fashion.

My application has the install section setup as described in many different
documents. And it does install sucessfully as "LocalSystem" and "Automatic".

[SC] GetServiceConfig SUCCESS

SERVICE_NAME: autobackup
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "I:\Program Files\Filebackup\AutoBackup.exe"
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : AutoBackup
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem

Microsoft's documentation states that on a Service start request, OnStart()
is called and must return within 30 seconds; otherwise, the aforementioned
error will occur.

The OnStart section of my code, for testing, just has an entry to write to
the application event log and that is all, so I am rather puzzled as to why
it should not return from OnStart within 30 secs.

protected override void OnStart(string[] args)
{
EventLog.WriteEntry("AutoBackupScheduler",
DateTime.Now.ToLongTimeString() + " - Started.");
}

I have tried various suggestions of adding the application directory to the
System path and to set the login to a userid and password rather than
"LocalSystem" but to no avail.

As this kind of thing cannot be debugged, at least in any way I know of, I
am enquiring of the general community to see if there are any further
suggestions.

By the way, there are no dependencies as least that I am aware of (i.e, no
required DLL's that I have created).

Thanks very much for any assiastance and have a great day!!!
 
Debug by either:

Attaching the debugger to the service process,
or
Install the debug version of your service (don't forget the PDB file!). In
OnStart() make a call to System.Diagnostics.Debugger.Break().
Start the service, and when the Break() function is called, you can have VS
attach to the process and away you go.
You *might* need to have VS open with the project loaded, and have the
debugger connect to the running instance (so you can step through the code).

Was doing this recently for some services we were writing for a client.
 
I am afraid from what I have read that none of your suggestions will work.

There is no point in trying to attach the debugger as in order for this to
be of any use the service MUST be in a STARTed state. Mine never gets
started as suggested by the error I receive.

Also, it clearly states in the MS Documentation that you cannot install a
breakpoint in Onstart as this will cause the error I am having. The reason it
causes this error is that the breakpoint will or may not allow OnStart to
return within 30 secs as it supposed to and as is stated in the MS Docs.

This is what makes this type of problem so hard to troubleshoot.

OnStart is used to initiate a thread that includes the code for the service.
So, OnStart starts the thread and then returns to the SCM (Service Control
Manager) within 30 secs. and normally everything is OK.

Anway, this is my understanding from doing a lot of research.

Thanks for the replying.

Brendan Green said:
Debug by either:

Attaching the debugger to the service process,
or
Install the debug version of your service (don't forget the PDB file!). In
OnStart() make a call to System.Diagnostics.Debugger.Break().
Start the service, and when the Break() function is called, you can have VS
attach to the process and away you go.
You *might* need to have VS open with the project loaded, and have the
debugger connect to the running instance (so you can step through the code).

Was doing this recently for some services we were writing for a client.

Mike B said:
The following error occurs on trying to start a Windows Service that is
based
on a C# application I am writing:

[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely
fashion.

My application has the install section setup as described in many
different
documents. And it does install sucessfully as "LocalSystem" and
"Automatic".

[SC] GetServiceConfig SUCCESS

SERVICE_NAME: autobackup
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "I:\Program Files\Filebackup\AutoBackup.exe"
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : AutoBackup
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem

Microsoft's documentation states that on a Service start request,
OnStart()
is called and must return within 30 seconds; otherwise, the aforementioned
error will occur.

The OnStart section of my code, for testing, just has an entry to write to
the application event log and that is all, so I am rather puzzled as to
why
it should not return from OnStart within 30 secs.

protected override void OnStart(string[] args)
{
EventLog.WriteEntry("AutoBackupScheduler",
DateTime.Now.ToLongTimeString() + " - Started.");
}

I have tried various suggestions of adding the application directory to
the
System path and to set the login to a userid and password rather than
"LocalSystem" but to no avail.

As this kind of thing cannot be debugged, at least in any way I know of, I
am enquiring of the general community to see if there are any further
suggestions.

By the way, there are no dependencies as least that I am aware of (i.e, no
required DLL's that I have created).

Thanks very much for any assiastance and have a great day!!!
 
Thanks very much but I have resolved the problem myself.

It was a silly mistake that prevented the instantiation of my service class.
 
I see you've found a solution to your problem.

I just wanted to say that all of my suggestions DO work. I've done it
before.

Mike B said:
I am afraid from what I have read that none of your suggestions will work.

There is no point in trying to attach the debugger as in order for this to
be of any use the service MUST be in a STARTed state. Mine never gets
started as suggested by the error I receive.

Also, it clearly states in the MS Documentation that you cannot install a
breakpoint in Onstart as this will cause the error I am having. The reason
it
causes this error is that the breakpoint will or may not allow OnStart to
return within 30 secs as it supposed to and as is stated in the MS Docs.

This is what makes this type of problem so hard to troubleshoot.

OnStart is used to initiate a thread that includes the code for the
service.
So, OnStart starts the thread and then returns to the SCM (Service Control
Manager) within 30 secs. and normally everything is OK.

Anway, this is my understanding from doing a lot of research.

Thanks for the replying.

Brendan Green said:
Debug by either:

Attaching the debugger to the service process,
or
Install the debug version of your service (don't forget the PDB file!).
In
OnStart() make a call to System.Diagnostics.Debugger.Break().
Start the service, and when the Break() function is called, you can have
VS
attach to the process and away you go.
You *might* need to have VS open with the project loaded, and have the
debugger connect to the running instance (so you can step through the
code).

Was doing this recently for some services we were writing for a client.

Mike B said:
The following error occurs on trying to start a Windows Service that is
based
on a C# application I am writing:

[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely
fashion.

My application has the install section setup as described in many
different
documents. And it does install sucessfully as "LocalSystem" and
"Automatic".

[SC] GetServiceConfig SUCCESS

SERVICE_NAME: autobackup
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "I:\Program
Files\Filebackup\AutoBackup.exe"
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : AutoBackup
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem

Microsoft's documentation states that on a Service start request,
OnStart()
is called and must return within 30 seconds; otherwise, the
aforementioned
error will occur.

The OnStart section of my code, for testing, just has an entry to write
to
the application event log and that is all, so I am rather puzzled as to
why
it should not return from OnStart within 30 secs.

protected override void OnStart(string[] args)
{
EventLog.WriteEntry("AutoBackupScheduler",
DateTime.Now.ToLongTimeString() + " - Started.");
}

I have tried various suggestions of adding the application directory to
the
System path and to set the login to a userid and password rather than
"LocalSystem" but to no avail.

As this kind of thing cannot be debugged, at least in any way I know
of, I
am enquiring of the general community to see if there are any further
suggestions.

By the way, there are no dependencies as least that I am aware of (i.e,
no
required DLL's that I have created).

Thanks very much for any assiastance and have a great day!!!
 
I would have just created the service as a console app first, and debug it
easily. Then create as a service when your done.
 
So are you saying that the Microsoft documentation is incorrect?
(i.e., if the service deos not start that you can still attach the debugger
and debug the situaution)?

If this is the case and since the service is not running, what do you attach
the debugger to?

Brendan Green said:
I see you've found a solution to your problem.

I just wanted to say that all of my suggestions DO work. I've done it
before.

Mike B said:
I am afraid from what I have read that none of your suggestions will work.

There is no point in trying to attach the debugger as in order for this to
be of any use the service MUST be in a STARTed state. Mine never gets
started as suggested by the error I receive.

Also, it clearly states in the MS Documentation that you cannot install a
breakpoint in Onstart as this will cause the error I am having. The reason
it
causes this error is that the breakpoint will or may not allow OnStart to
return within 30 secs as it supposed to and as is stated in the MS Docs.

This is what makes this type of problem so hard to troubleshoot.

OnStart is used to initiate a thread that includes the code for the
service.
So, OnStart starts the thread and then returns to the SCM (Service Control
Manager) within 30 secs. and normally everything is OK.

Anway, this is my understanding from doing a lot of research.

Thanks for the replying.

Brendan Green said:
Debug by either:

Attaching the debugger to the service process,
or
Install the debug version of your service (don't forget the PDB file!).
In
OnStart() make a call to System.Diagnostics.Debugger.Break().
Start the service, and when the Break() function is called, you can have
VS
attach to the process and away you go.
You *might* need to have VS open with the project loaded, and have the
debugger connect to the running instance (so you can step through the
code).

Was doing this recently for some services we were writing for a client.

The following error occurs on trying to start a Windows Service that is
based
on a C# application I am writing:

[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely
fashion.

My application has the install section setup as described in many
different
documents. And it does install sucessfully as "LocalSystem" and
"Automatic".

[SC] GetServiceConfig SUCCESS

SERVICE_NAME: autobackup
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "I:\Program
Files\Filebackup\AutoBackup.exe"
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : AutoBackup
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem

Microsoft's documentation states that on a Service start request,
OnStart()
is called and must return within 30 seconds; otherwise, the
aforementioned
error will occur.

The OnStart section of my code, for testing, just has an entry to write
to
the application event log and that is all, so I am rather puzzled as to
why
it should not return from OnStart within 30 secs.

protected override void OnStart(string[] args)
{
EventLog.WriteEntry("AutoBackupScheduler",
DateTime.Now.ToLongTimeString() + " - Started.");
}

I have tried various suggestions of adding the application directory to
the
System path and to set the login to a userid and password rather than
"LocalSystem" but to no avail.

As this kind of thing cannot be debugged, at least in any way I know
of, I
am enquiring of the general community to see if there are any further
suggestions.

By the way, there are no dependencies as least that I am aware of (i.e,
no
required DLL's that I have created).

Thanks very much for any assiastance and have a great day!!!
 
Back
Top