Re: Called ServiceBase.Run(), but never receive OnStart()?
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Wed, 23 Jan 2008 10:03:06 +0100
"Jeff Dege" <jdege@xxxxxxxxxxxxxx> wrote in message news:13pdlg9a60a8j21@xxxxxxxxxxxxxxxxxxxxx
On Tue, 22 Jan 2008 21:54:34 +0100, Willy Denoyette [MVP] wrote:
"Jeff Dege" <jdege@xxxxxxxxxxxxxx> wrote in message
news:13pcddf851ldjba@xxxxxxxxxxxxxxxxxxxxx
On Tue, 22 Jan 2008 18:04:58 +0100, Willy Denoyette [MVP] wrote:But you are reading from the registry before you are actually writing to
"Jeff Dege" <jdege@xxxxxxxxxxxxxx> wrote in message
news:13pc68fdtp86c53@xxxxxxxxxxxxxxxxxxxxx
I have a service, written in C# and .NET V2.0.50727, that works fine
on
some machines, but hangs on start on others.
In MyService.Main(), I read the registry for a few initialization
settings, most important of which for our purposes is the name of the
logfile.
I then create a new MyService object, and pass it to
ServiceBase.Run(). (MyService is, of course, derived from
ServiceBase).
I write a log message immediately before
ServiceBase.Run(myServiceObject).
MyService.OnStart(args) writes a log message immediately on being
called.
On the machines where this works, I see, in the logfile, the two
messages one immediately following the other.
On the machines where it does not, when I try to start the service,
the progress bar seems to stop, half-way, then after a long wait, I
get a failed to start dialog. In the Services Manager, the service
displays a "Starting" status, with the start, restart, and stop
buttons greyed out.
What exactly are you doing before calling ServiceBase.Run() and what
are you doing in your service class constructor? Are you sure you call
ServiceBase.Run(), before the 30 seconds time-out period after the SCM
started the service process?
Before ServiceBase.Run()? Read the registry for some initialization
settings. Write a startup message to the log file. Write an about to
call ServiceBase.Run() message to the log file.
the log file, what's important is to know the time you entered Main
(before you read from the registry) and the time at which you are
calling Run, the difference between those may not exceed 30 seconds. I
would suggest you to write a message to the eventlog when entering Main
and calling Run.
So the reading of the registry settings is consistently taking just
enough time that the log message prior to ServiceBase.Run() occcurs in
less than 30 seconds, but the immediately following log message in
MyService.OnStart() does not?
Seems unlikely. I'll check it, but I'd be very surprised if this were
the issue.
--
What, me .sig?
But you don't log a message prior to the read from the registry, so you have no idea when this happens. Anyway, fact is that your service does not start and this fact is logged in the eventlog. Now there are two possible causes for this; 1) the service control manager (SCM) did not receive a registration request within 30 seconds after starting the service process, or 2) the service did not signal it's state within 30 seconds after receiving a start request from the SCM.
SCM --> start service process
service process -- 1 --> SCM
SCM -- 2 --> Service
If one of both 1 or 2 result in a time out, the service will be flagged as "Failed to start" and a message will be logged in the eventlog.
So, you need to know when the service *process* was started, that is, when Main was entered and compare this to the time when Run was called, the time difference must be less than 30 seconds.
Willy.
.
- Follow-Ups:
- Re: Called ServiceBase.Run(), but never receive OnStart()?
- From: Jeff Dege
- Re: Called ServiceBase.Run(), but never receive OnStart()?
- References:
- Called ServiceBase.Run(), but never receive OnStart()?
- From: Jeff Dege
- Re: Called ServiceBase.Run(), but never receive OnStart()?
- From: Willy Denoyette [MVP]
- Re: Called ServiceBase.Run(), but never receive OnStart()?
- From: Jeff Dege
- Re: Called ServiceBase.Run(), but never receive OnStart()?
- From: Willy Denoyette [MVP]
- Re: Called ServiceBase.Run(), but never receive OnStart()?
- From: Jeff Dege
- Called ServiceBase.Run(), but never receive OnStart()?
- Prev by Date: Re: example wtih multithreading and ping
- Next by Date: Re: which one is faster/better > or >=
- Previous by thread: Re: Called ServiceBase.Run(), but never receive OnStart()?
- Next by thread: Re: Called ServiceBase.Run(), but never receive OnStart()?
- Index(es):