By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

.NET based services not starting reliably: ServiceController.Start() method

P: n/a
We're using the ServiceController class provided by the .NET Framework,
programming in C#. We are using the Start() method to start a service from
another service. This works fine most of the time, but occasionally after a
system startup (where the service doing the starting of the other is
automatically started by Windows XP) the ServiceController's Start() method
fails to start the other service. It is probably throwing an
InvalidOperationException in these cases (we know it is in some cases). Is
there any way to tell why Windows cannot start the service, and are there
known problems with the reliability of the Start() method? It works most of
the time, but occasionally after unsealing the XP OS, or after a restart,
this fails. We're trying retries of calls to the Start() method, but after
3 retries it still fails inexplicably.

We need to find out if:

1.. this is a known problem
2.. how long does it wait, and is this wait time adequate?
3.. can this happen if one of the services upon which the service being
started depends takes too long to start? We are quite sure the actual
service being started takes almost no time to execute its two lines that
consist of starting a worker thread in its OnStart() method.
4.. is there some reason this would only occur after an unseal or system
restart (that's the only time we see it)?
5.. there are any known fixes or workarounds to this problem
Feb 22 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Arnie wrote:
5.. there are any known fixes or workarounds to this problem


It depends on the nature of the second service and what resources it
requires.

So, what might be happening is that the OS and all it's services are not
fully up, or loaded into memory, or else in the process of loading and
accessible but very slow.

I would advise, if possible, adding a Timer interval of say 30s-60s if you
can afford that to insure that the OS is fully loaded.
Feb 22 '06 #2

P: n/a
If your into Debugging Tools for Windows
(http://www.microsoft.com/whdc/devtoo...g/default.mspx) you can use
Global Flags to set the executable's start up program to WinDbg (don't use a
managed code debugger, it won't work). Set winDbg to beak on first chance
CLR exceptions, then continue the service under the debugger. Also, the
service has to be allowed to interact with the desktop. Be quick because you
must continue the debugger in the service's start up time period (30
seconds?).
--
David Douglass
MCSD for Microsoft .NET
"Arnie" wrote:
We're using the ServiceController class provided by the .NET Framework,
programming in C#. We are using the Start() method to start a service from
another service. This works fine most of the time, but occasionally after a
system startup (where the service doing the starting of the other is
automatically started by Windows XP) the ServiceController's Start() method
fails to start the other service. It is probably throwing an
InvalidOperationException in these cases (we know it is in some cases). Is
there any way to tell why Windows cannot start the service, and are there
known problems with the reliability of the Start() method? It works most of
the time, but occasionally after unsealing the XP OS, or after a restart,
this fails. We're trying retries of calls to the Start() method, but after
3 retries it still fails inexplicably.

We need to find out if:

1.. this is a known problem
2.. how long does it wait, and is this wait time adequate?
3.. can this happen if one of the services upon which the service being
started depends takes too long to start? We are quite sure the actual
service being started takes almost no time to execute its two lines that
consist of starting a worker thread in its OnStart() method.
4.. is there some reason this would only occur after an unseal or system
restart (that's the only time we see it)?
5.. there are any known fixes or workarounds to this problem

Feb 22 '06 #3

P: n/a
in VS 2005 IDE, load up the Service project/solution -- then start the
service, then in VS 2005 "attach to process" -- find your service EXE in the
list of running processing and click "Attach" button -- now place
breakpoints where you think you might need them -- stop your service and
start the service and see if it traps your error -- if this only happens at
system startup, then you'll need to have your service output to EventLog at
approprioate points in the code so you can see where and why it is breaking
(the old fashion way of debugging before we even had debuggers).

you may also want to look into how the service was installed -- did you
specify .NET framework and/or other services as dependant service? You can
do this manually or you can do it via the Windows Installer 3.0 that comes
with VS 2005.

Rob.

"Arnie" <je*****************@msn.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
We're using the ServiceController class provided by the .NET Framework,
programming in C#. We are using the Start() method to start a service
from another service. This works fine most of the time, but occasionally
after a system startup (where the service doing the starting of the other
is automatically started by Windows XP) the ServiceController's Start()
method fails to start the other service. It is probably throwing an
InvalidOperationException in these cases (we know it is in some cases).
Is there any way to tell why Windows cannot start the service, and are
there known problems with the reliability of the Start() method? It works
most of the time, but occasionally after unsealing the XP OS, or after a
restart, this fails. We're trying retries of calls to the Start() method,
but after 3 retries it still fails inexplicably.

We need to find out if:

1.. this is a known problem
2.. how long does it wait, and is this wait time adequate?
3.. can this happen if one of the services upon which the service being
started depends takes too long to start? We are quite sure the actual
service being started takes almost no time to execute its two lines that
consist of starting a worker thread in its OnStart() method.
4.. is there some reason this would only occur after an unseal or system
restart (that's the only time we see it)?
5.. there are any known fixes or workarounds to this problem

Feb 22 '06 #4

P: n/a
thanks for the reply. We'll look into delaying things a bit to see if that
helps.

We only see the issue after many power cycles.

So our fix is taking the form of:
-delay a bit and try again
-catch an exception if the second service doesn't start and retry
-lastly force a reboot of the system

-jeff

"John Bailo" <ja*****@texeme.com> wrote in message
news:2_********************@speakeasy.net...
Arnie wrote:
5.. there are any known fixes or workarounds to this problem


It depends on the nature of the second service and what resources it
requires.

So, what might be happening is that the OS and all it's services are not
fully up, or loaded into memory, or else in the process of loading and
accessible but very slow.

I would advise, if possible, adding a Timer interval of say 30s-60s if you
can afford that to insure that the OS is fully loaded.

Feb 23 '06 #5

P: n/a
thanks for the reply. Since we see this so infrequently (like once in 100
powercycles) we would like to only trap it when it fails. Starting the
second service will throw an exception on a fail so it looks like this would
help.

What we would really like is for MS to fix this?

-jeff

"David Douglass" <Da***********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
If your into Debugging Tools for Windows
(http://www.microsoft.com/whdc/devtoo...g/default.mspx) you can
use
Global Flags to set the executable's start up program to WinDbg (don't use
a
managed code debugger, it won't work). Set winDbg to beak on first chance
CLR exceptions, then continue the service under the debugger. Also, the
service has to be allowed to interact with the desktop. Be quick because
you
must continue the debugger in the service's start up time period (30
seconds?).
--
David Douglass
MCSD for Microsoft .NET
"Arnie" wrote:
We're using the ServiceController class provided by the .NET Framework,
programming in C#. We are using the Start() method to start a service
from
another service. This works fine most of the time, but occasionally
after a
system startup (where the service doing the starting of the other is
automatically started by Windows XP) the ServiceController's Start()
method
fails to start the other service. It is probably throwing an
InvalidOperationException in these cases (we know it is in some cases).
Is
there any way to tell why Windows cannot start the service, and are there
known problems with the reliability of the Start() method? It works most
of
the time, but occasionally after unsealing the XP OS, or after a restart,
this fails. We're trying retries of calls to the Start() method, but
after
3 retries it still fails inexplicably.

We need to find out if:

1.. this is a known problem
2.. how long does it wait, and is this wait time adequate?
3.. can this happen if one of the services upon which the service being
started depends takes too long to start? We are quite sure the actual
service being started takes almost no time to execute its two lines that
consist of starting a worker thread in its OnStart() method.
4.. is there some reason this would only occur after an unseal or
system
restart (that's the only time we see it)?
5.. there are any known fixes or workarounds to this problem

Feb 23 '06 #6

P: n/a
thanks for the input, this is helpful.

We know that the secondary service simply fails to start, and it happens
very infrequently.
After 10's of power cycles.

Any idea if doing an umanaged service is more reliable?

-jeff

"Rob R. Ainscough" <ro*****@pacbell.net> wrote in message
news:Oz****************@TK2MSFTNGP09.phx.gbl...
in VS 2005 IDE, load up the Service project/solution -- then start the
service, then in VS 2005 "attach to process" -- find your service EXE in
the list of running processing and click "Attach" button -- now place
breakpoints where you think you might need them -- stop your service and
start the service and see if it traps your error -- if this only happens
at system startup, then you'll need to have your service output to
EventLog at approprioate points in the code so you can see where and why
it is breaking (the old fashion way of debugging before we even had
debuggers).

you may also want to look into how the service was installed -- did you
specify .NET framework and/or other services as dependant service? You
can do this manually or you can do it via the Windows Installer 3.0 that
comes with VS 2005.

Rob.

"Arnie" <je*****************@msn.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
We're using the ServiceController class provided by the .NET Framework,
programming in C#. We are using the Start() method to start a service
from another service. This works fine most of the time, but occasionally
after a system startup (where the service doing the starting of the other
is automatically started by Windows XP) the ServiceController's Start()
method fails to start the other service. It is probably throwing an
InvalidOperationException in these cases (we know it is in some cases).
Is there any way to tell why Windows cannot start the service, and are
there known problems with the reliability of the Start() method? It
works most of the time, but occasionally after unsealing the XP OS, or
after a restart, this fails. We're trying retries of calls to the
Start() method, but after 3 retries it still fails inexplicably.

We need to find out if:

1.. this is a known problem
2.. how long does it wait, and is this wait time adequate?
3.. can this happen if one of the services upon which the service being
started depends takes too long to start? We are quite sure the actual
service being started takes almost no time to execute its two lines that
consist of starting a worker thread in its OnStart() method.
4.. is there some reason this would only occur after an unseal or system
restart (that's the only time we see it)?
5.. there are any known fixes or workarounds to this problem


Feb 23 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.