
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
List What Processes an Assembly Is Loaded In
|
1091
// Now pause.
if (scStateService.CanPauseAndContinue)
{
scStateService.Pause( );
// Wait up to 60 seconds for stop.
scStateService.WaitForStatus(ServiceControllerStatus.Paused,
serviceTimeout);
}
break;
}
In order to be sure that the Status property is correct on the service, the application
should call Refresh to update it before testing the value of the Status property. Once
the application is done with the service, call the
Close method.
scStateService.Refresh( );
Console.WriteLine("Status: " + scStateService.Status.ToString( ));
// Close it.
scStateService.Close( );
Discussion
Services run many of the operating system functions today. They usually run under a
system account (
LocalSystem, NetworkService, LocalService) or a specific user
account that has been granted specific permissions and rights. If your application
uses a service, then this is a good way to determine if everything for the service to run
is set up and configured properly before your application attempts to use it. Not all
applications depend on services directly. But if your application does, or you have
written a service as part of your application, it can be handy to have an easy way to
check the status of your service and possibly correct the situation.
See Also ...