wcf - Windows Service Never Restarted from C# Code -


i have written code restart windows service never works properly. service able stop never start again. project self hosted wcf service inside windows service. below code.

restart method

    public static void restartservice(string servicename)     {         try         {             servicecontroller svc = new servicecontroller(servicename);             if (svc.status == servicecontrollerstatus.running) svc.stop();             svc.waitforstatus(servicecontrollerstatus.stopped, new system.timespan(0, 0, 20));             svc.start();             svc.waitforstatus(servicecontrollerstatus.running, new system.timespan(0, 0, 20));             svc.dispose();         }         catch (exception ex)         {             logging.writeexception(ex);         }     } 

main program

static class program {     /// <summary>     /// main entry point application.     /// </summary>     static void main()     {         try         {             servicebase[] servicestorun =             {                  new myservice()              };             servicebase.run(servicestorun);         }         catch (exception)         {          }     } 

the correct way manage restart of services using windows service recovery actions, described here.

they allow tell service control manager in event of failure, including restart actions, how many times attempt restart, , how long wait between attempts.

this way more robust write in service code itself.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -