我的工作进程是一个.net核心控制台应用程序.我如何像Windows服务一样托管它?
因为在当前的实现中,我认为如果我把它打包成像nssm这样的东西,它会因为Console.ReadKey()而被卡住; 但我仍然需要处理停止事件.
public class Program
{
private Program()
{
}
public static void Main()
{
var services = new ServiceCollection();
var startup = new Startup();
startup.ConfigureServices(services);
var serviceProvider = services.BuildServiceProvider();
var workerService = serviceProvider.GetService<WorkerService>();
workerService.Run();
Console.WriteLine("Listening for messages. Hit any key to quit.");
Console.ReadKey();
workerService.Stop();
}
}
Run Code Online (Sandbox Code Playgroud)