does not run a program RRS feed

All replies

  • One solution is to run it without debugging. Then the console window remains open when the program is finished.

    Another option is to add a line of code to pause execution at the end of "Main". For example:

    Console.WriteLine("Press ENTER to exit.");


    Monday, July 16, 2018 6:34 PM
  • Hi imad S,

    Thank you for posting here.

    For your question, please try the ways below.

    1. Please try codes below. 

    Console.ReadLine();//waits for Enter key
    Console.ReadKey();//waits for any key (except for modifier keys).
    Console.Read();//waits for Enter key

    2. Try Ctrl + F5 to run your Console program in Visual Studio, this will add a pause with "Press any key to continue..." automatically.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, July 17, 2018 6:49 AM
  • Just to explain further:

    Whenever a program runs it will start at a given 'entry point' - for your Console application this will be the Main method.

    The code will then be executed in order, though possibly branching off where it hits a 'flow control' command such as a while loop or a foreach etc (I wlll ignore asynchronous code for simplicity here!)

    When the program gets to the very end of the Main method it will exit.

    This is how programs work. If you want your application to loop around indefinitely or pause and wait for a user to do something and so on, then you have to explicitly code for that. E.g. Using the Console.ReadLine() command (which sits and waits for the user to type something) as Alberto Poblacion said in his post above.

    Tuesday, July 17, 2018 7:37 AM
  • This question has been answered hundreds of times before.

    Sam Hobbs

    Tuesday, July 17, 2018 6:09 PM
  • That's a default behaviour of console application in c#. To make sure console application result window open till you close manually or close by pressing any key or enter key you need to add any of the following commands in your program.

    // Window close on Enter Key Press
    // Window close on any key press

    To know more about how to create and run applications in c#, check following article.

    Wednesday, July 18, 2018 9:38 AM