Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make GUI wait for windows service?

I wrote a windows service and a gui for it. Of course gui mainly depends on the service. Is there a way for gui to wait for the service? Sometimes I need to reload service config from the gui and restart the service.

I was thinking about 2 solutions: 1. using while and sleep to wait for service controller status to change (of course the simplest solution :P) 2. implementin INotifiPropertyChanged interface somewhere (this looks to complicated for this trivial problem).

I was wondering is there more elegant way of doing it? Is there an event that I am missing somewhere?

like image 380
kyrisu Avatar asked Aug 10 '09 13:08

kyrisu


2 Answers

ServiceController has a method WaitForStatus where you pass it an argument of type ServiceControllerStatus. You can use it like this:

controller.WaitForStatus(ServiceControllerStatus.Running);
like image 88
Tommy Carlier Avatar answered Sep 18 '22 00:09

Tommy Carlier


I'd probably spawn a seperate thead to simply poll and see when your service controller status has changed, when the change occurs kill this thread. Then simply re spawn the thread when you need to start re-poll

Darknight

like image 21
Darknight Avatar answered Sep 21 '22 00:09

Darknight