Comment puis-je retarder mon service créé dans Windows Server 2003 et Windows XP?
-
21-12-2019 - |
Question
J'ai fait un service (winserviceproject) il y a plusieurs jours et je veux que cela démarre automatique mais avec un temps retardé ... J'ai trouvé une solution mais cela ne peut pas m'aider à m'aider: http://support.microsoft.com/kb/193888/fr-us
Je modifie le regedit à HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ WinserviceProject, mais cela ne fonctionne pas.
i Ajoutez une valeur multi-chaîne (dépendez-vous) et définissez de nombreux services avant ... cela fonctionne mais ne vous plaise pas.
La solution dont j'ai besoin avec le temps, réglées de temps et exécutez le service après cette heure.Si j'ai besoin d'ajouter du code à mon service, je le ferai.
merci.
La solution
Je résolvez le problème avec ce code !! / p>
RÉSARTSVICE STATIQUE STATIQUE PUBLIQUE (STRING SERVICENNAME, INT TimeOutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
int millisec1 = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
// count the rest of the timeout
//int millisec2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - millisec1);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
// ...
}
}