Home All Groups Group Topic Archive Search About

.NET 2.0 and Windows Service

Author
10 Mar 2006 12:28 AM
Mike B
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!!!

Author
10 Mar 2006 1:20 AM
Brendan Green
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.

Show quote
"Mike B" <Mi***@discussions.microsoft.com> wrote in message
news:29A37376-57E0-40A1-B6A1-770427408B98@microsoft.com...
> 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!!!
Author
10 Mar 2006 1:45 AM
Mike B
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.

Show quote
"Brendan Green" wrote:

> 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" <Mi***@discussions.microsoft.com> wrote in message
> news:29A37376-57E0-40A1-B6A1-770427408B98@microsoft.com...
> > 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!!!
>
>
>
Author
14 Mar 2006 1:37 AM
Brendan Green
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.

Show quote
"Mike B" <Mi***@discussions.microsoft.com> wrote in message
news:0CA15D6E-EAD7-499C-B263-3765C1E0D54A@microsoft.com...
>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" wrote:
>
>> 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" <Mi***@discussions.microsoft.com> wrote in message
>> news:29A37376-57E0-40A1-B6A1-770427408B98@microsoft.com...
>> > 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!!!
>>
>>
>>
Author
14 Mar 2006 3:02 AM
William Stacey [MVP]
I would have just created the service as a console app first, and debug it
easily.  Then create as a service when your done.

--
William Stacey [MVP]
Author
14 Mar 2006 3:08 AM
Mike B
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?

Show quote
"Brendan Green" wrote:

> 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" <Mi***@discussions.microsoft.com> wrote in message
> news:0CA15D6E-EAD7-499C-B263-3765C1E0D54A@microsoft.com...
> >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" wrote:
> >
> >> 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" <Mi***@discussions.microsoft.com> wrote in message
> >> news:29A37376-57E0-40A1-B6A1-770427408B98@microsoft.com...
> >> > 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!!!
> >>
> >>
> >>
>
>
>
Author
10 Mar 2006 4:18 AM
Mike B
Thanks very much but I have resolved the problem myself.

It was a silly mistake that prevented the instantiation of my service class.

Show quote
"Mike B" wrote:

> 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!!!

AddThis Social Bookmark Button