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

Windows Service - Reporting Error at Start

P: n/a
Joe
C# .NET 2.0

I've got a Windows Service that works exactly as I expect it to. However,
it does rely on a few Configuration settings. If the customer doesn't
configure it correctly, the service shouldn't start.

So I've put in some try...catchs, but what I'm not sure how to do is not
allow the service to start. If attempted to start with the NET START
command, throwing an exception keeps the service from starting, but the
message reported back is :

The MyService service is starting.
The MyService service could not be started.

The service did not report an error.

So how do I report this error? Writing it to the EvenLog doesn't resolve
it, although there is an entry in there as expected.

Secondly, if the service is started via the SMC, the service doesn't start
as expected, but I'm given the following error:

The MyService service on Local Computer started and then stopped. Some
services stop automatically if they have no work to do, for example, the
Performance Logs and Alerts service.

So how do I prevent the service from starting (although in both these
cases, the service doesn't actually start) and make whatever appropriate
error reports necessary?

Thanx!

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 30 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
> I've got a Windows Service that works exactly as I expect it to. However,
it does rely on a few Configuration settings. If the customer doesn't
configure it correctly, the service shouldn't start.


Perhaps, in OnStart you just don't call the base class' OnStart if the
criteria aren't met?

That ought to keep it from starting.
Mar 30 '06 #2

P: n/a
Hi,

IIRC if you throw an exception in the onstart and do not catch it the
service does not start and you get an error msg.

Additionally I would insert a event log with a detailed description of what
happened
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Joe" <js*************@logicor.com> wrote in message
news:op***************@jsheble-laptop.logicorphx2.com...
C# .NET 2.0

I've got a Windows Service that works exactly as I expect it to. However,
it does rely on a few Configuration settings. If the customer doesn't
configure it correctly, the service shouldn't start.

So I've put in some try...catchs, but what I'm not sure how to do is not
allow the service to start. If attempted to start with the NET START
command, throwing an exception keeps the service from starting, but the
message reported back is :

The MyService service is starting.
The MyService service could not be started.

The service did not report an error.

So how do I report this error? Writing it to the EvenLog doesn't resolve
it, although there is an entry in there as expected.

Secondly, if the service is started via the SMC, the service doesn't start
as expected, but I'm given the following error:

The MyService service on Local Computer started and then stopped. Some
services stop automatically if they have no work to do, for example, the
Performance Logs and Alerts service.

So how do I prevent the service from starting (although in both these
cases, the service doesn't actually start) and make whatever appropriate
error reports necessary?

Thanx!

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Mar 31 '06 #3

P: n/a
Joe
I do have a try...catch (was pretty sure my original message stated as
much). And there are EventLog entries, but it still doesn't perform as
expected...

On Fri, 31 Mar 2006 07:00:15 -0700, Ignacio Machin ( .NET/ C# MVP )
<ignacio.machin AT <dot.state.fl.us>> wrote:
Hi,

IIRC if you throw an exception in the onstart and do not catch it the
service does not start and you get an error msg.

Additionally I would insert a event log with a detailed description of
what
happened


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Apr 3 '06 #4

P: n/a
Joe
I found my own answer, and it was something I overlooked. The ServiceBase
class has an ExitCode property. Setting this, and still re-throwing the
exception in the OnStart does what I expect and want it to do.

Thanx!

On Mon, 03 Apr 2006 08:10:27 -0700, Joe <js*************@logicor.com>
wrote:
I do have a try...catch (was pretty sure my original message stated as
much). And there are EventLog entries, but it still doesn't perform as
expected...

On Fri, 31 Mar 2006 07:00:15 -0700, Ignacio Machin ( .NET/ C# MVP )
<ignacio.machin AT <dot.state.fl.us>> wrote:
Hi,

IIRC if you throw an exception in the onstart and do not catch it the
service does not start and you get an error msg.

Additionally I would insert a event log with a detailed description of
what
happened



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Apr 3 '06 #5

P: n/a
Just curious. I have looked everywhere in VS 2005 for the Windows
Service Project Template. I can't find it anywhere. Were you able to
find it?

Apr 3 '06 #6

P: n/a
Joe
if you mean the project wizard within the IDE itself, then yes... if you
mean the physical files that actually make up the template, then no...

On Mon, 03 Apr 2006 11:53:19 -0700, tdavisjr <td******@gmail.com> wrote:
Just curious. I have looked everywhere in VS 2005 for the Windows
Service Project Template. I can't find it anywhere. Were you able to
find it?


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Apr 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.