Hi,
I wrote a Windows service for a client a few months ago, and the client has
now asked me to modify it so that it shuts itself down under certain
circumstances e.g. a catastrophic failure of the network, SQL Server
connectivity problems etc.
I've tried to explain that this probably isn't a very good idea nor is it
even necessary because the service has sufficient error and exception
handling code to take account of such situations and take remedial action
accordingly, but my client is insistent, citing the fact that "lots of
Microsoft services shut themselves down sometimes..."
So I'm looking for some advice, please.
Firstly, do you agree with me that Windows services shutting themselves down
is bad practice? I've searched on Google to see if I can find anything to
back me up, but have drawn a bit of a blank so far.
Secondly, is it actually possible for a Windows service written in C# (v1.1)
to shut itself down?
Any assistance gratefully received.
Mark 7 6153
It all depends on the business situation. Those services that are started and
stopped on demand (such as MSIEXEC) have special purposes, different from
what this situation sounds like. On the face of it, you are right and the
client is wrong. Unfortunately, this goes against the marketing philosophy
that the client is always right, doesn't it?
The only way I know to have a service deliberately stop itself is the brute
force method - have it throw an unhandled exception.
--Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Mark Rae" wrote: Hi,
I wrote a Windows service for a client a few months ago, and the client has now asked me to modify it so that it shuts itself down under certain circumstances e.g. a catastrophic failure of the network, SQL Server connectivity problems etc.
I've tried to explain that this probably isn't a very good idea nor is it even necessary because the service has sufficient error and exception handling code to take account of such situations and take remedial action accordingly, but my client is insistent, citing the fact that "lots of Microsoft services shut themselves down sometimes..."
So I'm looking for some advice, please.
Firstly, do you agree with me that Windows services shutting themselves down is bad practice? I've searched on Google to see if I can find anything to back me up, but have drawn a bit of a blank so far.
Secondly, is it actually possible for a Windows service written in C# (v1.1) to shut itself down?
Any assistance gratefully received.
Mark
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:F0**********************************@microsof t.com... It all depends on the business situation. Those services that are started and stopped on demand (such as MSIEXEC) have special purposes,
That's what I thought...
different from what this situation sounds like.
Quite right - this is just a bog-standard data processing service - every
five minutes it sniffs a particular directory on a remote VMS FTP server in
Canada and processes any files it finds up there before deleting them.
On the face of it, you are right and the client is wrong.
Which is never a happy position for a jobbing contractor to find himself
in... :-)
Unfortunately, this goes against the marketing philosophy that the client is always right, doesn't it?
Oh indeed. Unless it is really bad for my reputation, the client always gets
what he wants, and I simply smile sweetly and raise the invoice... ;-)
The only way I know to have a service deliberately stop itself is the brute force method - have it throw an unhandled exception.
Ouch... I *really* don't fancy that very much...
couldnt you just instead of "stopping it" instead put the thread into
an extended sleep? I have done this on occassion for a service which
demands a sql server, and if there is a connectivity error, I set it to
sleep for 5 minutes, in the hopes that the server is just rebooting for
maintnance.
"mwolf" <mw***@realmagnet.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com... couldnt you just instead of "stopping it" instead put the thread into an extended sleep? I have done this on occassion for a service which demands a sql server, and if there is a connectivity error, I set it to sleep for 5 minutes, in the hopes that the server is just rebooting for maintnance.
See my OP - I already have this sort of exception handling built in, but the
client has "specifically" asked for it to shut itself down...
hmmm if its runing as an admin, I think you should be able to do a
process start and run
net stop servicename
probably not the most elegant way, but think it would work, but havent
tried it
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in
news:uc**************@TK2MSFTNGP14.phx.gbl: Secondly, is it actually possible for a Windows service written in C# (v1.1) to shut itself down?
I'm not going to argue the merits of this, but if you want to do it, you
can use the ServiceController class:
ServiceController sc = new ServiceController("MyServiceName");
sc.Stop();
-mdb
"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xn****************************@207.46.248.16. .. ServiceController sc = new ServiceController("MyServiceName"); sc.Stop();
That sounds promising - I'll give it a try - thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ross Bennett |
last post by:
Ahoy, Folks!
I've been looking all over for this, but I just can't seem to shake any
documentation out of the MSDN or from Google. I've reviewed every .NET
article on developing Windows...
|
by: Claire |
last post by:
Running XP pro, SP2. Visual studio .NET 2003. App written in C#
I have written an application that hides itself when run and shows a
notification icon in the system tray.
If the main form is...
|
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...
|
by: Mark Rae |
last post by:
Hi,
I'm looking for advice concerning what to do if a Windows service does not
find a "viable" working environment at startup.
E.g. I have a Windows service which does the following:
1)...
|
by: carbon_dragon |
last post by:
Ok, so here is the problem. I'm working on a headless server program
implemented as a .NET C# Console project. There is a UPS mounted to
this server (though not a windows compliant UPS). I can only...
| |
by: Shawn Meyer |
last post by:
Hello,
I have a windows service. When the onstart fires, my app creates two
threads. The first is a processing thread and the second is a watcher that
makes sure the everything is ok with the...
|
by: jez123456 |
last post by:
Hi Experts
I've written a c# windows service which runs another program at certain
intervals. The other program may take upto 20 minutes to complete it's tasks.
My question is what happens to...
|
by: Derek Hart |
last post by:
I have a vb.net winforms application that I want to run every time the
server starts up (it will be running on a server, and it is okay to have a
user interface). I have had a ton of trouble...
|
by: ArkJ |
last post by:
Hello.
I have a little problem. I created a little Service which uses SIP, all works rather well, but when I want to shut it down in the Services panel, it looks as if it's shut down, but in fact...
|
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: 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...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |