473,320 Members | 1,926 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,320 software developers and data experts.

Force Windows Service to stop running after exception is handled

I'm developing a Windows Service and just added a standard try... catch
exception handler to its OnStart() routine. I would like to know how to
force the service to abort its startup when an exception is encountered. In
my current version, the exception handler logs the exception, but then the
service continues to run. I'd like it to NOT run after logging the
exception.

Thanks!
Nov 16 '05 #1
2 18520
David,
The "easiest" way is to remove the try/catch in the OnStart routine, or at
least include throw in the catch clause...

For if the OnStart throws an exception ServiceBase does not allow the
service to start & if AutoLog is True, logs the fact it didn't start for
you. I don't remember if it logs the exception details, which can be
handy...

Hope this helps
Jay

"David Hunt" <A@B.COM> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I'm developing a Windows Service and just added a standard try... catch
exception handler to its OnStart() routine. I would like to know how to
force the service to abort its startup when an exception is encountered.
In my current version, the exception handler logs the exception, but then
the service continues to run. I'd like it to NOT run after logging the
exception.

Thanks!

Nov 16 '05 #2
Thanks. I think I'll log the Exception explicitly and then throw a new one
just to force it to not start (I need both to happen; log exception +
service NOT start).
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uk**************@TK2MSFTNGP11.phx.gbl...
David,
The "easiest" way is to remove the try/catch in the OnStart routine, or at
least include throw in the catch clause...

For if the OnStart throws an exception ServiceBase does not allow the
service to start & if AutoLog is True, logs the fact it didn't start for
you. I don't remember if it logs the exception details, which can be
handy...

Hope this helps
Jay

"David Hunt" <A@B.COM> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
I'm developing a Windows Service and just added a standard try... catch
exception handler to its OnStart() routine. I would like to know how to
force the service to abort its startup when an exception is encountered.
In my current version, the exception handler logs the exception, but then
the service continues to run. I'd like it to NOT run after logging the
exception.

Thanks!


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
2
by: karl | last post by:
I have a windows service that kicks off a 'monitor' thread which in turn kicks off 4 additional threads. These 4 threads basically are listen on a designated socket and report back any errors...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
4
by: Kris | last post by:
I have a Windows Service in C# talking to a serial port and using Remoting. It also uses several COM objects. On customer's computer the service will occassionally hang somewhere - the service...
8
by: Jerry Camel | last post by:
I want my service to terminate automatically if the specified parameters are invalid. I tried to use a servicecontroller component to attach to the service, but I think that it's failing because...
3
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with...
5
by: Primera | last post by:
I use the following method to stop the WMI service: string serviceName = "Windows Management Instrumentation" public static void stopService(string serviceName) { ServiceController services =...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
5
by: sonali_reddy123 | last post by:
Hello all, I am trying to develop an application which will run as a windows service. The application should have Normal options available with service like start, stop and pause but along...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.