简体   繁体   English

如何将控制台构建添加到 C# windows 服务应用程序并显示控制台?

[英]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.

相关问题 有没有办法让 dll 不显示在构建文件中但仍在 ac# 控制台应用程序中使用? - Is there a way to have dlls not show up in the build file but are still used in a c# console app? windows 服务和更新 c# 控制台应用程序 - windows service & updating c# console app 如何使用Visual Studio 2010将Windows控制台应用程序C#项目更改为Windows Service? - How to change Windows console app C# project into Windows Service using Visual Studio 2010? C#:Windows控制台应用程序到Windows服务 - C#: Windows Console Application to Windows Service 如何从任务管理器启动的 C# Windows 应用程序中显示控制台 output? - How do you show console output from C# Windows app started by task manager? 从任务计划程序运行时,Windows服务器上的计划的C#控制台应用程序不显示控制台 - Scheduled c# console app on windows server does not show console when ran from task scheduler C#Windows服务和控制台应用程序合二为一 - C# Windows Service and Console Application in one c#Windows服务控制台.Writeln - c# Windows Service Console.Writeln 运行 C# 控制台应用程序作为 Windows 服务 - Running a C# console application as a Windows service 如何在具有Windows应用程序输出类型的C#程序上显示控制台 - How to show the console on a C# program with Windows application output type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM