473,657 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reset Windows Service Programatically

Hi All,

I have created a Windows Service. In the event of an Exception
occuring I would like to notify Windows to restart the service
as shown below:

<snip>

protected override void OnStart(string[] args)
{
ThreadStart starter = new ThreadStart(thi s.StartListenin g);
Thread threadWorker = new Thread(starter) ;

threadWorker.St art();
}

public void StartListening( )
{
try
{
...
}
catch (Exception)
{
RESTART THE SERVICE <<

}
}

<snip>

I'm having no joy with this...any ideas are appreciated :o)
Jul 21 '05 #1
1 1869
Hello,

Look into the use of the ServiceControll er class.

http://msdn.microsoft.com/library/de...tInstances.asp

Another way of approaching the problem is to create another thread in your
service whose job is to monitor the health of your threadWorker. If that
thread notices an error via some flag, monitoring the thread's IsAlive
property, or is signalled by the theadWorker, it can abort the threadWorker
if necessary and restart it.

Hope this helps.
--
Jeffrey Wynn
so********@nosp am.net
Replace -no-spa-m with "-op-to-nl-ine" and remove the dashes
"Ciaran" <ci****@inser o-technologies.co m> wrote in message
news:f4******** *************** **@posting.goog le.com...
Hi All,

I have created a Windows Service. In the event of an Exception
occuring I would like to notify Windows to restart the service
as shown below:

<snip>

protected override void OnStart(string[] args)
{
ThreadStart starter = new ThreadStart(thi s.StartListenin g);
Thread threadWorker = new Thread(starter) ;

threadWorker.St art();
}

public void StartListening( )
{
try
{
...
}
catch (Exception)
{
>> RESTART THE SERVICE <<

}
}

<snip>

I'm having no joy with this...any ideas are appreciated :o)

Jul 21 '05 #2

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

Similar topics

1
3692
by: Kannan | last post by:
Hello, I hope you guys can help me with a problem that I am facing... I have started the MSSqlServer service and SQLServerAgent services with a domain username and password. There are periodic password resets to this user. Security policies within the company dictate that the password for this domain account cannot be permenant. Would there be any way to automatically reset the pwd in these
1
1140
by: Dhans | last post by:
My requirements are, 1) To run a windows application (Which allows user to interact with that) inside a windows service. For that how do i set the service type to InteractiveMode by programatically ? 2) The application to be started my change in feature, so that I need to get that application .exe file from the Configuration file. But when try to do this the ConfigurationError occurs, Is there any other way in services to change the...
3
14910
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim swLog As StreamWriter = File.CreateText("C:\myLog.txt") swLog.WriteLine("My Windows Service has just started.") swLog.Close() : swLog.Flush() End Sub
2
1548
by: Amongin Ewinyu | last post by:
Hi, I'm trying to create a Windows service programmatically that will do the following: - When a user logs on, it will automatically run a service that uses BITS (Background Intelligent Transfer Service) to check for the most current version of a file and downloads this version. I have a wrapper class thats imported as a reference in order for me to be
1
379
by: Ciaran | last post by:
Hi All, I have created a Windows Service. In the event of an Exception occuring I would like to notify Windows to restart the service as shown below: <snip> protected override void OnStart(string args) {
10
1511
by: msnnews.msn.com | last post by:
hi there, i've got a photo gallery that programatically creates a subfolder for each gallery, if i delete the album in my site, it also deletes the subfolder, but resets my website and i lose the active sessions.. please help! whats the solution to this so it doesnt reset on delete? thanks, Paul
7
7222
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch this error. I want to restart my windows service every time the COM object throws an error. I use System.ServiceProcess.ServiceController to stop and start my service. But there is one thing I do not understand:
4
1612
by: Simon Harvey | last post by:
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?
1
4504
by: svandanapu | last post by:
Hi All, I written one windows service and its working fine. I Need to check the recovery settings of that service from one windows application. How do I can get the recovery settings of(first failure, second failure and third failure) a service programatically. can any one please help me in this regard. Thanks in advance Sivakumar V
0
8394
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
8825
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
8732
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
8503
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
6164
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
4152
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...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.