473,856 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Using a ServiceControll er 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
ServiceControll er 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",
3. The process disappears from the Task Manager.

Solutions involving ServiceControll ers 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 3410

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

Similar topics

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 if fname > 6 print fname Thanks!!!
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") TypeError: input() takes no keyword arguments While the library reference says the function is: input( )
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 address of my default gateway) instead the remode IP address:,, etc.... Thanks, --
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 : microsoft.public.dotnet.languages.csharp URL :...
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 having installed MS .NET Framework 2.0 Beta 2 on it, from http://www.microsoft.com/downloads/details.aspx?FamilyId=7ABD8C8F-287E-4C7E-9A4A-A4ECFF40FC8E&displaylang=en), but got the following message:
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 to render the page" I can view the reports with within Crystal Reports. The same issue was posted here with no solution:
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 number is not found on MSDN Online or any site on internet. The Stacktrace:
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)
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 array1 or array2 is unmodified, that is, they remain NULL. In this case, if allocation of array1 succeeds, and allocation of array2 fails, then array1 will be deallocated. What if new does modify the value of the int* array2 even if second allocation...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.