Pregunta

Hice un servicio (WinServiceProject) hace muchos días y quiero que este arranque automático pero con un tiempo retrasado ... encontré una solución, pero esto no puedo ayudarme: http://support.microsoft.com/kb/193888/en-us

Modifique la regedit en HKEY_LOCAL_MACHINE \ SISTEMA \ CurrentControlSet \ Services \ WinserviceProject pero esto no funciona.

Agrego el valor de Multi-String (dependedeService) y configura muchos servicios antes ... Esto funciona pero no te gusta que quiera.

La solución que necesito con el tiempo, establezca muchas veces y ejecute el servicio después de este tiempo.Si necesito agregar código a mi servicio, lo hare.

gracias.

¿Fue útil?

Solución

¡¡¡Resuelve el problema con este código!

RESTARTE ESTÁTICO PÚBLICO SERVICIO (NAME DE SERVICIO, 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
        {
            // ...
        }

    }

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top