473,322 Members | 1,307 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,322 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 1735
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.