DotNetCore.WindowsService icon indicating copy to clipboard operation
DotNetCore.WindowsService copied to clipboard

Question: How to use ExitCode?

Open sekmenhuseyin opened this issue 5 years ago • 0 comments

I want to restart the service if service stopped with an error. I found that you have something called exit code: https://github.com/PeterKottas/DotNetCore.WindowsService/blob/4c0052bef2217c3f6b3ec15a98e23335fc07aa88/Source/PeterKottas.DotNetCore.WindowsService/ExitCode.cs

How can I user it in here:

            ServiceRunner<CMailerService>.Run(config =>
            {                
                config.Service(serviceConfig =>
                {                   
                    serviceConfig.OnStop(service =>
                    {

                       //in here I want to restart the service if exitCode!=0
                        _serviceStoppedMail.SendServiceStoppedMail(ProjectConstants.RestartInfoMail, _lastError);


                        Log.Information("Service {0} is stopping...", name);
                        service.Stop();
                        Log.Information("Service {0} stopped", name);
                    });
                });
            });

sekmenhuseyin avatar Sep 13 '19 08:09 sekmenhuseyin