PDA

View Full Version : ServiceController.WaitForStatus() method query


ipsoftware
12-22-2004, 07:32 AM
I have the following code at the backend

void StopService(serviceName){
try{
ServiceController svc = new ServiceController(serviceName);
svc.Stop();
svc.WaitForStatus(ServiceControllerStatus.Stopped);
}
}
catch (Exception){
}

My Questions are:
(1) I am using svc.WaitForStatus(ServiceControllerStatus.Stopped); (no time out defined here, coz I don't know how long the service takes to stop...), I think there is a possibility that the code will be blocked forever here, right? just waiting , waiting for the "Stopped" status..How can I avoid this?
(2) In terms of excepion, what kinds of exceptions may occur when controlling a service, what I can think of is "access right exception", what else?

Thank you!!!