[英]How to add console build to a C# windows service app and have the console show up?
I've got a project that was originally built as a C# Windows Service in Visual Studio 2019. I've made changes to conditionally compile it both as a service and as a console app.我有一个项目,最初在 Visual Studio 2019 中构建为 C# Windows 服务。我已经进行了更改,以有条件地将其编译为服务和控制台应用程序。 The problem I'm having is that when the app is run in console mode, it runs as a background process and never shows the console.
我遇到的问题是,当应用程序在控制台模式下运行时,它作为后台进程运行并且从不显示控制台。 Is there some setting that will have this run as a normal console app?
是否有一些设置可以让它作为普通的控制台应用程序运行?
I know the app is indeed running because when I debug it, it will stop at my break points after it receives a data packet.我知道应用程序确实在运行,因为当我调试它时,它会在收到数据包后停在我的断点处。
I usually do this: (no need to conditionally compile)我通常这样做:(无需有条件地编译)
static void Main(string[] args)
{
if (Environment.UserInteractive)
{
Service s = new Service();
s.Start();
while (true)
{
Thread.Sleep(10000);
}
}
else
{
ServiceBase.Run(new ServiceClass());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.