473,386 Members | 1,720 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.

Service Stop Problem

Hi,
Is it generally acceptable that the SCM says that the service has
stopped but the service has spawn a thread which is still doing the cleanup
thing which keeps the process running.
Oct 6 '05 #1
4 1741
Not really. A service should not return from OnStop() until it has completed
cleaning up.

It should be noted that the SCM is a little smarter than just taking a
services word on if it has been stopped or not. Even if you have a thread
keeping your process alive, the SCM is likely to still kill it once the
accepted window for shutting down has elapsed.

Brendan
"Prasad" wrote:
Hi,
Is it generally acceptable that the SCM says that the service has
stopped but the service has spawn a thread which is still doing the cleanup
thing which keeps the process running.

Oct 6 '05 #2
Prasad,

When service is being stopped by SCM, you have an event handler right. You
can do the clean up operations over there, rather than depending on a thread
isolated from the regular SCM management.

Thanks and Regards,

Deepak Vasudevan
http://www.lavanyadeepak.tk/
http://deepakvasudevan.blogspot.com/
91 98400 26014
"Prasad" wrote:
Hi,
Is it generally acceptable that the SCM says that the service has
stopped but the service has spawn a thread which is still doing the cleanup
thing which keeps the process running.

Oct 12 '05 #3
It should be avoided, really confusing to operations people. However, there
doesn't seem to be a [good] work around for a dotnet service. The
ServiceController doesn't expose SetServiceStatus()... so I can't see how you
would set SERVICE_STATUS dwWaitHint, dwCheckPoint (estimated time/keep alive
respectively).

Someone mentioned DependantServices... you could kludge it IF you know some
absolute maximum time to Stop. Each DependantService gets 30 seconds to Stop.
Soooo, if you had a bunch of DummyServices... and the last one was your real
service... you might be able to get the time you need.

ServiceController.Stop() looks like this...

Anyone knows a good way to coordinate Stop time (SetServiceStatus) please
post it ;)

for (int num1 = 0; num1 < this.DependentServices.Length; num1++)
{
if (this.DependentServices[num1].Status !=
ServiceControllerStatus.Stopped)
{
this.DependentServices[num1].Stop();

this.DependentServices[num1].WaitForStatus(ServiceControllerStatus.Stopped,
new TimeSpan(0, 0, 30));
}
}
NativeMethods.SERVICE_STATUS service_status1 = new
NativeMethods.SERVICE_STATUS();
if (!UnsafeNativeMethods.ControlService(ptr1, 1,
&service_status1)) // SERVICE_CONTROL_STOP
{
Exception exception1 =
ServiceController.CreateSafeWin32Exception();
object[] objArray1 = new object[2] { this.ServiceName,
this.MachineName } ;
throw new
InvalidOperationException(Res.GetString("StopServi ce", objArray1),
exception1);
}
"Prasad" wrote:
Hi,
Is it generally acceptable that the SCM says that the service has
stopped but the service has spawn a thread which is still doing the cleanup
thing which keeps the process running.

Nov 5 '05 #4
Win32 has SetServiceStatus() to coordinate estimated stop time and that you
are making progress... we just don't have access to it.

/jhd

"Brendan Grant" wrote:
Not really. A service should not return from OnStop() until it has completed
cleaning up.

It should be noted that the SCM is a little smarter than just taking a
services word on if it has been stopped or not. Even if you have a thread
keeping your process alive, the SCM is likely to still kill it once the
accepted window for shutting down has elapsed.

Brendan
"Prasad" wrote:
Hi,
Is it generally acceptable that the SCM says that the service has
stopped but the service has spawn a thread which is still doing the cleanup
thing which keeps the process running.

Nov 5 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down on the time that it takes to Stop. The Service...
2
by: Owe Armandt | last post by:
I have a service where I start up the worker thread from OnStart and also stop the thread from OnStop. My problem is if the service by itself decides to stop because of some problem it cannot...
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 :...
4
by: Kris | last post by:
I have a Windows Service in C# talking to a serial port and using Remoting. It also uses several COM objects. On customer's computer the service will occassionally hang somewhere - 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...
8
by: Jerry Camel | last post by:
I want my service to terminate automatically if the specified parameters are invalid. I tried to use a servicecontroller component to attach to the service, but I think that it's failing because...
2
by: Nathan | last post by:
I have created a windows service but am having difficulties handling exceptions in the OnStart. What I want to do is if an exeception occurs during any of the code executed during the OnStart is...
6
by: eroc.spam | last post by:
Hello- I'm working with a .NET windows service that can potentially take up to 10 minutes to shutdown. I would like to make it so that SCM doesn't timeout before the service actually stops, but...
5
by: Tom | last post by:
Using multiple System.Timers.Timer objects in a Windows Service for performing multi-thread activities in a periodic fashion. Timers are AutoReset=false, to only have a single timer execution...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
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...

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.