互斥启动
This commit is contained in:
parent
51170e68b1
commit
ef4ebf738a
@ -1,7 +1,6 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace FastGithub
|
||||
{
|
||||
@ -15,8 +14,7 @@ namespace FastGithub
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
ConsoleUtil.DisableQuickEdit();
|
||||
|
||||
var contentRoot = Path.GetDirectoryName(Environment.GetCommandLineArgs().First());
|
||||
var contentRoot = Path.GetDirectoryName(Environment.ProcessPath);
|
||||
if (string.IsNullOrEmpty(contentRoot) == false)
|
||||
{
|
||||
Environment.CurrentDirectory = contentRoot;
|
||||
@ -26,7 +24,7 @@ namespace FastGithub
|
||||
Args = args,
|
||||
ContentRootPath = contentRoot
|
||||
};
|
||||
CreateWebApplication(options).Run();
|
||||
CreateWebApplication(options).Run(singleton: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using FastGithub.DomainResolve;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -45,17 +46,17 @@ namespace FastGithub
|
||||
/// <summary>
|
||||
/// 运行主机
|
||||
/// </summary>
|
||||
/// <param name="host"></param>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="singleton"></param>
|
||||
public static void Run(this IHost host, bool singleton = true)
|
||||
public static void Run(this WebApplication app, bool singleton)
|
||||
{
|
||||
var logger = host.Services.GetRequiredService<ILoggerFactory>().CreateLogger(nameof(FastGithub));
|
||||
var logger = app.Services.GetRequiredService<ILoggerFactory>().CreateLogger(nameof(FastGithub));
|
||||
if (UseCommand(logger) == false)
|
||||
{
|
||||
using var mutex = new Mutex(true, "Global\\FastGithub", out var firstInstance);
|
||||
if (singleton == false || firstInstance)
|
||||
{
|
||||
HostingAbstractionsHostExtensions.Run(host);
|
||||
app.Run();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user