Have you had a look at the ServiceController Class? Something like this should get you started.
ServiceController sc = new ServiceController("ServiceName");
switch (sc.Status)
{
case ServiceControllerStatus.Running:
break;
case ServiceControllerStatus.Stopped:
break;
case ServiceControllerStatus.Paused:
break;
}
If you would like to avoid constantly polling on a timer, you could have a look at WaitForStatus. Have your background workers always waiting for a specified status to enable buttons, disable buttons or whatever.
This is a very basic example, but to answer your question about infinite loop - no. see my comments and debug step this, you will understand why.
ServiceController sc = new ServiceController("ServiceName");
for (;;)
{
// for pauses execution, waiting for stopped status.
sc.WaitForStatus(ServiceControllerStatus.Stopped);
// continues when stopped status signaled, disable button
// for waiting for running status.
sc.WaitForStatus(ServiceControllerStatus.Running);
//continues when running status signaled, enable button
// for will continue but wait for stopped status signal
}
This is why I recommended doing this check in a background worker or just something off of the main thread so that your entire application does not get jammed up while waiting for status changes.