473,386 Members | 1,706 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,386 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 1853
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: 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
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.