Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alright, finally implemented this. I've posted it as a separate answer as I had already come to this conclusion in the original update to my question, which was posted prior to the first answer.</p> <p>Again, the <code>StartService()</code>, <code>StopService()</code> and <code>RestartService()</code> methods follow the conventions outlined in the examples and such already referenced in the question itself (i.e. they wrap Start/Stop behavior to avoid "already started/stopped"-type exceptions) with the addendum that if a <code>Service</code> is passed in (as is the case below), <code>Refresh()</code> is called on that service before checking its <code>Status</code>.</p> <pre><code>public static void RestartServiceWithDependents(ServiceController service, TimeSpan timeout) { int tickCount1 = Environment.TickCount; // record when the task started // Get a list of all services that depend on this one (including nested // dependencies) ServiceController[] dependentServices = service.DependentServices; // Restart the base service - will stop dependent services first RestartService(service, timeout); // Restore dependent services to their previous state - works because no // Refresh() has taken place on this collection, so while the dependent // services themselves may have been stopped in the meantime, their // previous state is preserved in the collection. foreach (ServiceController dependentService in dependentServices) { // record when the previous task "ended" int tickCount2 = Environment.TickCount; // update remaining timeout timeout.Subtract(TimeSpan.FromMilliseconds(tickCount2 - tickCount1)); // update task start time tickCount1 = tickCount2; switch (dependentService.Status) { case ServiceControllerStatus.Stopped: case ServiceControllerStatus.StopPending: // This Stop/StopPending section isn't really necessary in this // case as it doesn't *do* anything, but it's included for // completeness &amp; to make the code easier to understand... break; case ServiceControllerStatus.Running: case ServiceControllerStatus.StartPending: StartService(dependentService, timeout); break; case ServiceControllerStatus.Paused: case ServiceControllerStatus.PausePending: StartService(dependentService, timeout); // I don't "wait" here for pause, but you can if you want to... dependentService.Pause(); break; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload