NextTurn 6 年之前
父節點
當前提交
a7c5334f10
共有 3 個文件被更改,包括 21 次插入6 次删除
  1. 4 4
      src/WinSW.Tests/WinSW.Tests.csproj
  2. 9 1
      src/WinSW/Program.cs
  3. 8 1
      src/WinSW/WrapperService.cs

+ 4 - 4
src/WinSW.Tests/WinSW.Tests.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFrameworks>net471;netcoreapp5.0</TargetFrameworks>
+    <TargetFrameworks>net471;net5.0</TargetFrameworks>
     <LangVersion>latest</LangVersion>
   </PropertyGroup>
 
@@ -20,7 +20,7 @@
     </PackageReference>
   </ItemGroup>
 
-  <ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp5.0'">
+  <ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
     <PackageReference Include="System.Reflection.Metadata" Version="1.8.1" />
     <Reference Include="System.ServiceProcess" />
   </ItemGroup>
@@ -39,11 +39,11 @@
 
   <Target Name="Copy" BeforeTargets="AfterBuild">
 
-    <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp5.0'">
+    <ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
       <_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net5.0\WinSW.runtimeconfig*.json" />
     </ItemGroup>
 
-    <ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp5.0'">
+    <ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
       <_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net461\System.ValueTuple.dll" />
     </ItemGroup>
 

+ 9 - 1
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
+                    }
                 }),
             };
 

+ 8 - 1
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)