我围绕“Windows 服务”的概念开发了一个 .NET Framework 控制台应用程序。在Main()
方法中,我有类似的东西:
internal static class Program {
private static void Main(string[] args) {
if (Environment.UserInteractive) {
var myService = new MyService();
myService.Test(args);
} else {
ServiceBase.Run(new ServiceBase[] { new MyService() });
}
}
}
MyService
是从 .NETSystem.ServiceProcess.ServiceBase
类派生的类,并MyService
覆盖其OnStart()
方法、OnStop()
方法等。我想在 Kubernetes 中运行这些控制台应用程序。我面临的问题是执行立即结束,因为应用程序没有“安装”为集群中的真正窗口服务。我已经阅读了.NET 中的工作人员服务,但我想知道是否可以维护旧代码。