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

Windows Service, How does one make a service "fail" properly?

Ahoy, Folks!

I've been looking all over for this, but I just can't seem to shake any
documentation out of the MSDN or from Google. I've reviewed every .NET
article on developing Windows Services in the MSDN I've located.

I'm developing a Windows Service application. This service reads its
configuration data from the system registry (HKLM) where it was deposited by
another "manager" application. No problems there.

The service uses a worker thread to do its work. The thread is created in
the OnStart() and signaled/joined/disposed in the OnStop(). Again, no
problems.

Everything works beautifully when:

1. The system administrator has set up everything properly, and
2. the foreign network resources are all reachable.

But of course, we as developers simply can't rely on:

1. The system administrator having set up everything properly, or
2. the foreign network resources being reachable.

Really, what we need is for the service application to have some way of
dying on its own. If a network resource goes down, we need the service to
stop. But more to the point, we need the SCM to know it has stopped on its
own accord. SCM needs to know that the service has "failed"...and hasn't
just been shut down by someone.

Calling "return" or throwing an exception in the "OnStart()" method isn't
even helpful for services still in the start-up process.. The SCM goes
merrily on and the process keeps running in the Task Manager--though it's
not actually doing anything since the worker thread was never created and
started.

Using a ServiceController instance doesn't do it, either. That appears to
the SCM as a normal shutdown--not a service failure. So none of the
recovery actions or restarts happen. (Also, there is MSDNful documentation
warning about the perils of a ServiceBase descendant using a
ServiceController to make things happen with itself.)

I've read articles where people were messing about with PInvoking calls to
the native code just to set the "Stopped" status flag in the SCM. But that
doesn't shut down the process the service is running within.

I'd really like to know the Intended Way of:

1. Shutting down a service from within the service, where
2. The SCM is appropriatedly notified that the service has "Stopped",
and
3. The process disappears from the Task Manager.

Solutions involving ServiceControllers don't seem to be appropriate, if only
because 2 is not satisfied. (That the Framework documentation specifically
contraindicates doing that carries a good deal of weight, incidentally.)

I'd appreciate any recommendations, pointers to documentation, or even
well-reasoned conjecture. :-) Oh! And I'm perfectly happy to entertain
that I've missed the point.

Most cordially,

Ross Bennett
Solution Developer <-- This does not mean I will develop your
photographs. That would be "Developer Solution"
Optical Image Technology, Inc.
Nov 15 '05 #1
0 3365

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

Similar topics

11
by: hokiegal99 | last post by:
How would I determine if a filename is greater than a certain number of characters and then truncate it to that number? For example a file named XXXXXXXXX.txt would become XXXXXX fname = files...
12
by: zhi | last post by:
Really confused, when I use keyword style argument as following: >>> input(prompt="hello") Traceback (most recent call last): File "<pyshell#52>", line 1, in -toplevel- input(prompt="hello")...
0
by: Vilmar | last post by:
Hi, Can Request.ServerVariables("REMOTE_ADDR") fail and catch the address of my default gateway in my local network?? What should I do? Sometimes brings 192.168.0.1(the address of my default...
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 :...
3
by: Gustavo L. Fabro | last post by:
Greetings! I'm testing VS 2005 Beta 2, and I've compiled a program that runs just fine on my computer (where VS is installed). I've tried to run this same program on another computer (after...
7
by: mrwoopey | last post by:
I have a asp.net application that uses the crystal report viewer control. It displays all of my reports but all of a sudden it started giving me the following error on ONLY two reports: "Fail...
0
by: Guilherme Silva | last post by:
Hi All, I found another problem with .NET about "fail to start monitoring". This one is different from any other because it only show this error without "Access Denied". Even the Excpetion...
1
by: Robbie Hatley | last post by:
Say I have an ifstream object, like so: #include <iostream> #include <fstream> int main(int, char* Sam) { std::ifstream Bob; Bob.open(Sam); std::string buffer; while (42)
4
by: simbasaurus | last post by:
Hello! I am trying to make sure that I clean up and free all the resources that I allocate in my code. In the following code, I am assuming that if new throws bad_alloc, than the value of...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.