From a7c5334f10c978f06cca5295f547c5d48a5d5cee Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Sat, 1 Dec 2018 00:00:00 +0800 Subject: [PATCH] Catch --- src/WinSW.Tests/WinSW.Tests.csproj | 8 ++++---- src/WinSW/Program.cs | 10 +++++++++- src/WinSW/WrapperService.cs | 9 ++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/WinSW.Tests/WinSW.Tests.csproj b/src/WinSW.Tests/WinSW.Tests.csproj index bff328d..9198df9 100644 --- a/src/WinSW.Tests/WinSW.Tests.csproj +++ b/src/WinSW.Tests/WinSW.Tests.csproj @@ -1,7 +1,7 @@  - net471;netcoreapp5.0 + net471;net5.0 latest @@ -20,7 +20,7 @@ - + @@ -39,11 +39,11 @@ - + <_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net5.0\WinSW.runtimeconfig*.json" /> - + <_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net461\System.ValueTuple.dll" /> diff --git a/src/WinSW/Program.cs b/src/WinSW/Program.cs index ee70da9..18943b4 100644 --- a/src/WinSW/Program.cs +++ b/src/WinSW/Program.cs @@ -102,7 +102,15 @@ namespace WinSW AutoRefresh(config); - ServiceBase.Run(new WrapperService(config)); + using var service = new WrapperService(config); + try + { + ServiceBase.Run(service); + } + catch + { + // handled in OnStart + } }), }; diff --git a/src/WinSW/WrapperService.cs b/src/WinSW/WrapperService.cs index 0f22ebd..e288b5e 100644 --- a/src/WinSW/WrapperService.cs +++ b/src/WinSW/WrapperService.cs @@ -586,7 +586,14 @@ namespace WinSW if (this.config.Priority is ProcessPriorityClass priority) { - process.PriorityClass = priority; + try + { + process.PriorityClass = priority; + } + catch (InvalidOperationException) + { + // exited + } } if (logHandler != null)