473,785 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Restarting a service from within itself using ServiceControll er

I've written a windows service am unsure how we're meant to handle
fatal errors once the service is already up and running. It also
doesn't seem to be mentioned in any of the books or examples I've
seen.

Most example services, if they encounter an error, simply stop
processing but stay active.

The route I've taken to avoid that is, on catching a fatal exception,
I create a ServiceControll er instance and issue a Stop command. This
then shuts down the service properly.

On the other hand, I'd also like to be able to restart the service.
It stands to reason I can't issue a stop followed by testing the
status and then starting it again ... because of course my own process
can't finish stopping while I'm in it waiting :)

So, what are we meant to do?

(Unfortunately, in this circumstance, we're interfacing with an
unmanaged DLL that, when it has an error, doesn't come back properly
until you restart the process that has called it).
Jun 27 '08 #1
1 1730
<se*******@gmai l.comwrote in message
news:68******** *************** ***********@j33 g2000pri.google groups.com...
I've written a windows service am unsure how we're meant to handle
fatal errors once the service is already up and running. It also
doesn't seem to be mentioned in any of the books or examples I've
seen.

Most example services, if they encounter an error, simply stop
processing but stay active.

The route I've taken to avoid that is, on catching a fatal exception,
I create a ServiceControll er instance and issue a Stop command. This
then shuts down the service properly.

On the other hand, I'd also like to be able to restart the service.
It stands to reason I can't issue a stop followed by testing the
status and then starting it again ... because of course my own process
can't finish stopping while I'm in it waiting :)

So, what are we meant to do?
I recommend throwing (or rethrowing) a fatal exception. Then, the service
control manager will handle the exception and possibly restart the service
as specified in the "Recovery" tab of the service definition. Why reinvent
the wheel?

Jun 27 '08 #2

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

Similar topics

0
3404
by: Ross Bennett | last post by:
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.
6
28622
by: Jacobus Terhorst | last post by:
Using C#: I tried: ServiceController me = new ServiceController(this.ServiceName); me.Stop(); it raises an exception: Cannot find Service I also tried:
23
7595
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an unrecoverable error occurs. When that case occurs, I create a ServiceController object and call the Stop() method. However - I get an exception thrown saying access denied. If I switch to using the LocalService account it works fine, but I lose...
8
1430
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 it's being called in the OnStart event (where I validate the parameters) and the service isn't fully running yet. How can I stop my service from within the service itself? Thanks. Jerry
6
3807
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop() ServiceController.WaitForStatus(ServiceControllerStatus.Stopped) ServiceController.start() but doesn´t works. It seems waitforstatus instruction is the last
4
15937
by: Simon Verona | last post by:
My software relies on a third party data provider to a propretary database. In turn the third party database relies on a Windows Service that runs on the server to supply the data... The problem is that from time to time this service dies without warning. Is there any way that I can write another small service or similar (using vb.net) that checks at regular intervals that the service is running and restart it if it isn't???
6
9350
by: sergio.calleja | last post by:
Hi Everybody, i need to restart a windows service made with c# when an fixed event is raised. So to test it, I've added a servicecontroller to my service, and in the creation method, i've created a new thread to try to stop it. This is my code: public Service1() { // This call is required by the Windows.Forms Component Designer.
4
21756
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a webserver to see if service A needs to be updated. What service B does if it sees their is an update for service A is to download a new copy of the service A executable, stop service A, replace the executable with the new copy, and start service B...
4
8832
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... Following the samples online, we implemented a windows service in .Net. Like most services, there's a worker thread actually doing stuff in the background. The problem we've run into is how to get the service to exit when the worker thread has a fatal error *and* get the SCM to invoke the auto-restart configuration? The worker thread can error out while the parent thread in the server process chugs along. We can set the exit...
0
9643
marktang
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...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
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...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
isladogs
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...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4045
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
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.