468,248 Members | 1,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,248 developers. It's quick & easy.

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 1577
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Owe Armandt | last post: by
4 posts views Thread by Kris | last post: by
23 posts views Thread by Adam Clauss | last post: by
8 posts views Thread by Jerry Camel | last post: by
2 posts views Thread by Nathan | last post: by
6 posts views Thread by eroc.spam | last post: by
5 posts views Thread by Tom | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.