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("StopService", objArray1),
exception1);
}