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 6167
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*******@yaho o.nospammin.com > wrote in message
news:F0******** *************** ***********@mic rosoft.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... :-)
Unfortunatel y, 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***@realmagn et.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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 "specifical ly" 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******** ******@TK2MSFTN GP14.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 ServiceControll er class:
ServiceControll er sc = new ServiceControll er("MyServiceNa me");
sc.Stop();
-mdb
"Michael Bray" <mbray@makeDInt oDot_ctiusaDcom > wrote in message
news:Xn******** *************** *****@207.46.24 8.16... ServiceControll er sc = new ServiceControll er("MyServiceNa me"); 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 Services in the MSDN I've located.
I'm developing a Windows Service application. This service reads its
configuration data from the system registry (HKLM) where it was deposited by
another "manager" application. No problems there.
|
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 visible/restored to the desktop, and I tell windows to
restart, windows shuts down fine.
If the main form is minimized to the tray and I tell windows to restart,
other desktop apps close down fine but my program's icon remains sat in the
system...
|
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 stopping.
Please advise how to stop the service.
Thanks,
SP
|
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) connects to a remote FTP site and looks for certain files which it
downloads to a fileserver if it finds them;
|
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 talk to
the UPS over a special device driver.
Through this device driver I can detect that the UPS is going to notify
Windows 2000 server to shut down. So I start doing a graceful
termination. But Windows shuts down pretty quickly and there...
| |
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 first thread. When a problem is
detected the second (watcher) thread stops the processing thread and then
throws an exception. This exception does not stop the service like I would
think.
My question is, what is the best way for the watcher...
|
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 the other program if a user decides to
manually stop the service (or there was a power cut) when the tasks have not
fully completed?
Should I wrap the other program within a transaction?
|
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 converting the whole project to
a windows service (tons of apartment threading issues), so I want to run it
as a scheduled task or as a simpler windows service. What I mean by a
simpler windows service is to create a simple application that just calls...
|
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 it's not:
- when I try want to delete the .DLL file, I can't: the file is still locked
- if I "Start" my Service again, it refuses
I have to wait like ~20s, and then it is really shut down.
When I shut down the Service, and then try to Start it...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |