Application self-closing on demand

40 views Asked by At

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.

1

There are 1 answers

2
Sinatr On BEST ANSWER

Have you considered this approach?

public static void Main(...)
{
    while(true)
    {
        // do job

        if(exit condition)
            return;
    }
}