473,378 Members | 1,446 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.

Restarting a service from within itself using ServiceController

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 ServiceController 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 1689
<se*******@gmail.comwrote in message
news:68**********************************@j33g2000 pri.googlegroups.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 ServiceController 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
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...
6
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
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...
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...
6
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()...
4
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...
6
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...
4
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...
4
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...
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
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.