M
Mark
Hi...
I inherited some code where someone wanted to start/stop services and
display a little ... progress bar while waiting.
Originally it was implemented with
ServiceController.{Start|Stop}()
for (int i = 0; i < 60; i++)
{
Console.WriteLine (".");
try
{
ServiceController.WaitForStatus (desiredState, TimeSpan.FromSeconds(1));
}
catch
{//ignore}
if (ServiceController.Status == desiredState) break;
}
Knowing how expensive exception processing is, I tried replacing it with
if (ServiceController.Status == desiredState) break;
Thread.Sleep(1000);
I'm finding, however, that the direct comparison is never reached no matter
how long I wait. Unless WaitForStatus is called (and the exception that
comes with it, usually 4 or 5 seconds/exceptions), the comparison doesn't
work.
I didn't find anything in the docs about this; is this just a known oddity
of the ServiceController? Seems like WaitForStatus could at least have been
friendlier and returned some kind of boolean success rather than throw an
exception - like WaitForMultipleObjects in the old days.
thanks
Mark
I inherited some code where someone wanted to start/stop services and
display a little ... progress bar while waiting.
Originally it was implemented with
ServiceController.{Start|Stop}()
for (int i = 0; i < 60; i++)
{
Console.WriteLine (".");
try
{
ServiceController.WaitForStatus (desiredState, TimeSpan.FromSeconds(1));
}
catch
{//ignore}
if (ServiceController.Status == desiredState) break;
}
Knowing how expensive exception processing is, I tried replacing it with
if (ServiceController.Status == desiredState) break;
Thread.Sleep(1000);
I'm finding, however, that the direct comparison is never reached no matter
how long I wait. Unless WaitForStatus is called (and the exception that
comes with it, usually 4 or 5 seconds/exceptions), the comparison doesn't
work.
I didn't find anything in the docs about this; is this just a known oddity
of the ServiceController? Seems like WaitForStatus could at least have been
friendlier and returned some kind of boolean success rather than throw an
exception - like WaitForMultipleObjects in the old days.
thanks
Mark