Keep threads alive even if console app exits

后端 未结 1 1654
清酒与你
清酒与你 2021-01-20 04:38

I have a console app in C# that runs endlessly and looks something like this:

class Program
{
    static void Main(string[] args)
    {    
        while(tru         


        
相关标签:
1条回答
  • 2021-01-20 04:52

    A console app is going to kill all threads when the window is closed. Always. There is no way around that. The console window is directly linked to the process.

    You may wish to use a Windows application which you will have more fine grained control over the main application loop. This could be a Windows Service or a WinForm/WPF type of application (which doesn't even really have to have a UI if you don't want).

    If you want a Windows Application that still shows the console - this is a bit wonky, but you can find an example of how to do that here.

    0 讨论(0)
提交回复
热议问题