472,347 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 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 16705
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...
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?...
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...
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()...
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...
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...
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...
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...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.