Dotnet Service Status

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

How do you set the Checkpint and WaitHint in a dotnet service. Calling
QueryServiceStatus after I attempt to stop my service always returns 0 for
these values.

Bob
 
Good question. I don't think its possible [in a useful way]. I took a look at
ServiceController [in reflector] and it doesn't even have SetStatus imported.
The service handle is private anyway.

The only work around I can see [using dotnet ServiceController] is to create
a bunch of Dependant services. Given 1 RealService that needs max 5 minutes
to shutdown... you could create 10 instances of a DummyService. Services 1-10
would be DummyServices... service 11 is the RealService. The DummyService
would tell the RealService that Stop had started.

I know it's goofy... but there's not much to work with afaik. Here's the
code from ServiceController.Stop()... If you have/know a better workaround
let me know ;)

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);
}
 
Back
Top