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

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(this.StartListening);
Thread threadWorker = new Thread(starter);

threadWorker.Start();
}

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 1854
Hello,

Look into the use of the ServiceController 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********@nospam.net
Replace -no-spa-m with "-op-to-nl-ine" and remove the dashes
"Ciaran" <ci****@insero-technologies.com> wrote in message
news:f4*************************@posting.google.co m...
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(this.StartListening);
Thread threadWorker = new Thread(starter);

threadWorker.Start();
}

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
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...
1
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...
3
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...
2
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...
1
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...
10
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...
7
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...
4
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...
1
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...
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: 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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
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...

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.