Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stopping a service
Message
 
À
18/08/2010 14:39:25
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01477126
Message ID:
01477968
Vues:
44
>What is the proper way of stopping a service? If I do Stop, this generates two errors in the Event Viewer. So, obviously, this is not the proper way of doing that. Anyone has done that from the code?

Here's some code I use:
public static void StopService(string serviceName, int timeoutSeconds)

{
    using (ServiceController controller = new ServiceController(serviceName))
    {
        try
        {
            controller.Stop();
            controller.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(timeoutSeconds));
        }
        catch (InvalidOperationException ex)
        {
            // Service may already be stopped
        }
    }            
}
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform