单例运行
This commit is contained in:
		
							parent
							
								
									eb3ef70a78
								
							
						
					
					
						commit
						0bf8998d26
					
				@ -28,7 +28,6 @@ namespace FastGithub
 | 
				
			|||||||
            return Host
 | 
					            return Host
 | 
				
			||||||
                .CreateDefaultBuilder(args)
 | 
					                .CreateDefaultBuilder(args)
 | 
				
			||||||
                .UseWindowsService() 
 | 
					                .UseWindowsService() 
 | 
				
			||||||
                .UseBinaryPathContentRoot()
 | 
					 | 
				
			||||||
                .UseDefaultServiceProvider(c =>
 | 
					                .UseDefaultServiceProvider(c =>
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    c.ValidateOnBuild = false;
 | 
					                    c.ValidateOnBuild = false;
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,7 @@ using System;
 | 
				
			|||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Runtime.Versioning;
 | 
					using System.Runtime.Versioning;
 | 
				
			||||||
 | 
					using System.Threading;
 | 
				
			||||||
using static PInvoke.AdvApi32;
 | 
					using static PInvoke.AdvApi32;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FastGithub
 | 
					namespace FastGithub
 | 
				
			||||||
@ -25,11 +26,11 @@ namespace FastGithub
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 使用应用程序文件所在目录作为ContentRoot
 | 
					        /// 使用windows服务
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="hostBuilder"></param> 
 | 
					        /// <param name="hostBuilder"></param> 
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        public static IHostBuilder UseBinaryPathContentRoot(this IHostBuilder hostBuilder)
 | 
					        public static IHostBuilder UseWindowsService(this IHostBuilder hostBuilder)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var contentRoot = Path.GetDirectoryName(Environment.GetCommandLineArgs().First());
 | 
					            var contentRoot = Path.GetDirectoryName(Environment.GetCommandLineArgs().First());
 | 
				
			||||||
            if (contentRoot != null)
 | 
					            if (contentRoot != null)
 | 
				
			||||||
@ -37,14 +38,15 @@ namespace FastGithub
 | 
				
			|||||||
                Environment.CurrentDirectory = contentRoot;
 | 
					                Environment.CurrentDirectory = contentRoot;
 | 
				
			||||||
                hostBuilder.UseContentRoot(contentRoot);
 | 
					                hostBuilder.UseContentRoot(contentRoot);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return hostBuilder;
 | 
					            return WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(hostBuilder);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 运行主机
 | 
					        /// 运行主机
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="host"></param>
 | 
					        /// <param name="host"></param>
 | 
				
			||||||
        public static void Run(this IHost host)
 | 
					        /// <param name="singleton"></param>
 | 
				
			||||||
 | 
					        public static void Run(this IHost host, bool singleton = true)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (OperatingSystem.IsWindows() && TryGetCommand(out var cmd))
 | 
					            if (OperatingSystem.IsWindows() && TryGetCommand(out var cmd))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -59,10 +61,14 @@ namespace FastGithub
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                using var mutex = new Mutex(true, "Global\\FastGithub", out var firstInstance);
 | 
				
			||||||
 | 
					                if (singleton == false || firstInstance)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    HostingAbstractionsHostExtensions.Run(host);
 | 
					                    HostingAbstractionsHostExtensions.Run(host);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 获取控制指令
 | 
					        /// 获取控制指令
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user