diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs
index fd8dc61..d798dfb 100644
--- a/FastGithub/Program.cs
+++ b/FastGithub/Program.cs
@@ -27,8 +27,7 @@ namespace FastGithub
{
return Host
.CreateDefaultBuilder(args)
- .UseWindowsService()
- .UseBinaryPathContentRoot()
+ .UseWindowsService()
.UseDefaultServiceProvider(c =>
{
c.ValidateOnBuild = false;
diff --git a/FastGithub/WindowServiceExtensions.cs b/FastGithub/WindowServiceExtensions.cs
index 0981c95..02c640f 100644
--- a/FastGithub/WindowServiceExtensions.cs
+++ b/FastGithub/WindowServiceExtensions.cs
@@ -6,6 +6,7 @@ using System;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
+using System.Threading;
using static PInvoke.AdvApi32;
namespace FastGithub
@@ -25,11 +26,11 @@ namespace FastGithub
}
///
- /// 使用应用程序文件所在目录作为ContentRoot
+ /// 使用windows服务
///
- ///
+ ///
///
- public static IHostBuilder UseBinaryPathContentRoot(this IHostBuilder hostBuilder)
+ public static IHostBuilder UseWindowsService(this IHostBuilder hostBuilder)
{
var contentRoot = Path.GetDirectoryName(Environment.GetCommandLineArgs().First());
if (contentRoot != null)
@@ -37,14 +38,15 @@ namespace FastGithub
Environment.CurrentDirectory = contentRoot;
hostBuilder.UseContentRoot(contentRoot);
}
- return hostBuilder;
+ return WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(hostBuilder);
}
///
/// 运行主机
///
///
- public static void Run(this IHost host)
+ ///
+ public static void Run(this IHost host, bool singleton = true)
{
if (OperatingSystem.IsWindows() && TryGetCommand(out var cmd))
{
@@ -60,7 +62,11 @@ namespace FastGithub
}
else
{
- HostingAbstractionsHostExtensions.Run(host);
+ using var mutex = new Mutex(true, "Global\\FastGithub", out var firstInstance);
+ if (singleton == false || firstInstance)
+ {
+ HostingAbstractionsHostExtensions.Run(host);
+ }
}
}