Search code examples
c#.netcompact-framework

Application self-closing on demand


I have a console application that needs to be able to stay open listening to commands that are sent to it from a communication module.

I managed to do that by adding this :

Console.WriteLine("Press any key to close...");
Console.ReadLine();

The problem I'm having is that, through the communication I want to able someone to send me a command telling me to close the application.

Those two informations collides and I'm stuck on how to do it properly.


Solution

  • Have you considered this approach?

    public static void Main(...)
    {
        while(true)
        {
            // do job
    
            if(exit condition)
                return;
        }
    }