473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Windows Service - Reporting Error at Start

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
6 8672
> 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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: LarryH | last post by:
Hi all, I going thru the MCSD course and I am creating a Windows Service. The Service compiles with no errors and I can install it using "Installutil" with no problem. But when I go into Services...
6
by: Ashwin Kambli | last post by:
Hi, I am trying to write a Windows Service application using C#. I wrote a very trivial example (logs messages during Start and Stop events to the evenlog). I have no problem installing it (using...
2
by: Mark | last post by:
I created an extremely simple windows service that only writes to the EventLogs on Stop and Pause. I installed it using the InstallUtil.exe program, the output of which is below. It appears to be...
3
by: Chuck Bowling | last post by:
Ok, I'm not sure this is a C# question but here goes anyhow... I used this walkthru to create a windows service: ...
3
by: mpriem | last post by:
Hi, I am developing my very first Windows Service. I want to query AD every 5 minutes to generate a Report which I will use in a website. I use the following testcode, but the service won't...
6
by: uuyytt | last post by:
I have a Windows service from which I want to start Internet Explorer with a particular URL as an argument. I don't know why my code (shown below) doesn't work. I know that IExplore.exe starts as I...
2
by: =?Utf-8?B?Sm9obiBTLg==?= | last post by:
I developed a Windows Service application written in vb.net and have successfully installed it on many workstations (over 25 PCs). All workstations have Windows XP SP2 installed. There are two...
9
by: Yasir Zaheer | last post by:
I have made a windows service which is configured to start automatically at the system startup under the USER account type. The service is working perfectly fine when I try to start it manually,...
4
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
I've written a .net Windows service in C#. It works most of the time for most people. It is configured to automatically start when Windows boots. Sometimes it fails to start on Windows XP during...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.