473,407 Members | 2,598 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,407 software developers and data experts.

Prevent a service from stopping.

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 exception

- from OnStop(): the SCM waits for a long time, reports that the
service didn't respond in a timely fashion and then leaves the status
as stopping.
- from Dispose(): the SCM displays an error dialog with the exception
details and prompts me to select a debugger. If I select 'No' the
service is stopped.

..NET Framework 1.1
MSDE 2003
Windows 2000 SP4

Jan 13 '06 #1
5 17314
Set the 'CanStop' property of the service to false.

-mdb

ch***********@teleware.co.uk wrote in news:1137170528.586382.30670
@g47g2000cwa.googlegroups.com:
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 exception

Jan 13 '06 #2
Michael Bray <mbray@makeDIntoDot_ctiusaDcom> wrote in
news:Xn***************************@207.46.248.16:
Set the 'CanStop' property of the service to false.


Sorry one thing I didn't notice was that you said you only want to prevent
the service from stopping under certain conditions. If that's the case,
setting the CanStop property to false wouldn't quite suffice.

Here's a further suggestion. Set the CanStop property to false, as above.
But then you will need an application that the user can use to request a
stop. This app would then communicate with your service (via remoting,
perhaps) and if the condition is permitted, stop itself. You should be
able to do this by dynamically setting 'CanStop' to true, then connecting
to yourself with the ServiceController class and issuing the 'Stop'
command.

I haven't actually tried it, but I think that would work.

-mdb
Jan 13 '06 #3
Just s quick note - you wouldn't need remoting for controlling the service,
a ServiceController's ExecuteCommand method would suffice if you need just a
parameterless command not returning anything

"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xn****************************@207.46.248.16. ..
Michael Bray <mbray@makeDIntoDot_ctiusaDcom> wrote in
news:Xn***************************@207.46.248.16:
Set the 'CanStop' property of the service to false.


Sorry one thing I didn't notice was that you said you only want to prevent
the service from stopping under certain conditions. If that's the case,
setting the CanStop property to false wouldn't quite suffice.

Here's a further suggestion. Set the CanStop property to false, as above.
But then you will need an application that the user can use to request a
stop. This app would then communicate with your service (via remoting,
perhaps) and if the condition is permitted, stop itself. You should be
able to do this by dynamically setting 'CanStop' to true, then connecting
to yourself with the ServiceController class and issuing the 'Stop'
command.

I haven't actually tried it, but I think that would work.

-mdb

Jan 13 '06 #4
"Lebesgue" <no****@spam.jp> wrote in
news:O#*************@TK2MSFTNGP09.phx.gbl:
Just s quick note - you wouldn't need remoting for controlling the
service, a ServiceController's ExecuteCommand method would suffice if
you need just a parameterless command not returning anything


I've tried using the ExecuteCommand before but I couldn't get it to work.
I forget what the specific error was. Any tricks?

-mdb
Jan 13 '06 #5
You will have to specify "the specific error" This can be caused by numerous
reasons, insufficient privileges to control the service would be the first
thing to look at.

"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xn***************************@207.46.248.16.. .
"Lebesgue" <no****@spam.jp> wrote in
news:O#*************@TK2MSFTNGP09.phx.gbl:
Just s quick note - you wouldn't need remoting for controlling the
service, a ServiceController's ExecuteCommand method would suffice if
you need just a parameterless command not returning anything


I've tried using the ExecuteCommand before but I couldn't get it to work.
I forget what the specific error was. Any tricks?

-mdb

Jan 13 '06 #6

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...
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 :...
7
by: Steve Long | last post by:
In writing a Windows service with .NET, I'm noticing that the process for some services can not be killed with specifically stopping the service. If you try to kill the process with, say task...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
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...
2
by: matteo | last post by:
Hi everyboby, i wrote a c# service that every XXX minute launch a working thread on timer events, something like this: private void timer_Elapsed ( object status ) { // Worker thread...
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...
5
by: marccruz | last post by:
Hi, I am writing a Windows Service in C#. I want to gracefully fail the "protected override void OnStop()" function. To do this, I first tried throwing an Exception in the function. However,...
0
by: mattcfisher | last post by:
Hi, I have two windows services running together. One is the main program, and one is an "updater" wrapper for the main. The updater service starts and stops the main one (as in you should never...
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: 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: 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
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
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,...
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...
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.