From 6a61dfdafa5e48fe6ea2c83876e7de4534e52e70 Mon Sep 17 00:00:00 2001 From: Juan Date: Mon, 25 Sep 2017 17:26:47 +0100 Subject: [PATCH] Moved directory set to the Run method so it is there from the beginning --- Source/PeterKottas.DotNetCore.WindowsService/ServiceRunner.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/PeterKottas.DotNetCore.WindowsService/ServiceRunner.cs b/Source/PeterKottas.DotNetCore.WindowsService/ServiceRunner.cs index 2c88782..5f5c885 100644 --- a/Source/PeterKottas.DotNetCore.WindowsService/ServiceRunner.cs +++ b/Source/PeterKottas.DotNetCore.WindowsService/ServiceRunner.cs @@ -17,6 +17,8 @@ public static class ServiceRunner where SERVICE : IMicroService { public static int Run(Action> runAction) { + Directory.SetCurrentDirectory(PlatformServices.Default.Application.ApplicationBasePath); + var innerConfig = new HostConfiguration(); innerConfig.Action = ActionEnum.RunInteractive; innerConfig.Name = typeof(SERVICE).FullName; @@ -269,7 +271,6 @@ private static void StartService(HostConfiguration config, ServiceContr { if (!(sc.Status == ServiceControllerStatus.StartPending | sc.Status == ServiceControllerStatus.Running)) { - Directory.SetCurrentDirectory(PlatformServices.Default.Application.ApplicationBasePath); sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(1000)); Console.WriteLine($@"Successfully started service ""{config.Name}"" (""{config.Description}"")");