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

Stopping my Windows Service Programatically

Hi all,

Can anybody tel me how to programatically kill my service when an
exception occurs?

Whenever something bad happens I'd like to shut it down.

Also, is there a way to programatically restart my service at a set
interval or when a particular condition is met within the application?

Many thanks

Simon
Mar 6 '07 #1
4 1595
On 6 Mar, 12:19, Simon Harvey <notha...@hotmail.comwrote:
Hi all,

Can anybody tel me how to programatically kill my service when an
exception occurs?

Whenever something bad happens I'd like to shut it down.

Also, is there a way to programatically restart my service at a set
interval or when a particular condition is met within the application?

Many thanks

Simon
I do it this way:

ServiceController controller = new
ServiceController(ConfigSettings.QueueSettings.QCo nfig.ServiceName);
controller.Stop();

In this case I have the name of the service in my config as my
installer is designed to allow multiple installs on the same computer.

You can use the same controller instance to start services too.

Mar 6 '07 #2
Hi,

"Simon Harvey" <no******@hotmail.comwrote in message
news:e4****************@TK2MSFTNGP03.phx.gbl...
Hi all,

Can anybody tel me how to programatically kill my service when an
exception occurs?
Catching the exception is a better idea.
Whenever something bad happens I'd like to shut it down.
I think that treating the problem is a better solution
Also, is there a way to programatically restart my service at a set
interval or when a particular condition is met within the application?
What kind of problems are you seeing that is that difficult to handle?
Mar 6 '07 #3
On Tue, 06 Mar 2007 12:19:35 +0000, Simon Harvey wrote:
Hi all,

Can anybody tel me how to programatically kill my service when an
exception occurs?

Whenever something bad happens I'd like to shut it down.

Also, is there a way to programatically restart my service at a set
interval or when a particular condition is met within the application?

Many thanks

Simon
The ServiceContoller class is your friend. You can use it to start and stop
services based on set criteria.

If you want to start it at timed intervals you could use a timer and within
the appropriate event write the code that invokes the service controller
--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 6 '07 #4
On Mar 6, 11:08 pm, "Rad [Visual C# MVP]" <nos...@nospam.comwrote:
On Tue, 06 Mar 2007 12:19:35 +0000, Simon Harvey wrote:
Hi all,
Can anybody tel me how to programatically kill my service when an
exception occurs?
Whenever something bad happens I'd like to shut it down.
Also, is there a way to programatically restart my service at a set
interval or when a particular condition is met within the application?
Many thanks
Simon

The ServiceContoller class is your friend. You can use it to start and stop
services based on set criteria.

If you want to start it at timed intervals you could use a timer and within
the appropriate event write the code that invokes the service controller
--
Bits.Byteshttp://bytes.thinkersroom.com
Be aware of using class System.Timers.Timer, and not the one in
System.Windows.Forms. They dond work the same way.
Best regards
Oscar Acosta

Mar 7 '07 #5

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

Similar topics

5
by: CG | last post by:
Hi I have developed a Windows Service When I try to start the Service it tells me that it cannot start as there may not be any work to do When I comment out below line of code in my OnStart...
0
by: Daniel O'Brien | last post by:
Hi - any help with this would be greatly appreicated - it has already had me confused for a good few hours! I am using Visual Studio 2003 and the .NET framework 1.1. I have a C# Windows...
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 :...
0
by: GTS | last post by:
Hi, I have created my application to run as windows service. It is developed using VC++ on Windows 2000 platform. It is working fine with Windows 2000. But I am seeing problems in Windows 2003...
7
by: Gene | last post by:
I have a Windows Service (VB.NET) that runs 24/7. It queries a Web service 5 to 10 times per hour. About 2 or 3 times a month, it fails. The log indicates that it sends the request to the Web...
0
by: Glen Wolinsky | last post by:
I am creating a Windows service that will check a request queue (database) for pending requests. It will then process each individual request until completed, wait a set time interval and then...
5
by: chris.hearson | last post by:
How do I programmatically prevent a service from stopping? I want to be able to keep my service running (started), under certain conditions, when a user tries to stop it. I have tried throwing an...
6
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
10
by: archana | last post by:
Hi all, I am having one windows service which is updating to database. On 'Onstop i want to wait till current updation complete. How will i do this? Because if i write some lengthy code on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.