Pausing the console program before it returns

  • Thread starter Thread starter Marin
  • Start date Start date
M

Marin

Right now my solution to this is adding Console.ReadLine at the end but I'm
wondering if it's possible to do it automatically?

If I chose "Start without debug" it does just that, it pauses right before
the console window closes, but "Start with debug" closes the window right
away.
 
Marin said:
Right now my solution to this is adding Console.ReadLine at the end but
I'm
wondering if it's possible to do it automatically?

Of course, if you start a console program from a console window, the console
window will remain open when the program finishes. The problem arises only
when you start the program by launching it directly (so it has to create its
own console window).

You may be able to make a shortcut to the .exe file and set the attributes
of the shortcut so that the window will remain there when the program ends.
 
Marin said:
If I chose "Start without debug" it does just that, it pauses right before
the console window closes, but "Start with debug" closes the window right
away.

My solution: put a breakpoint at the closing } of Main.

That way, when I run it in debug mode, I get to see the output.
And when I run the release program from a console prompt, I get to see
the output.
 
Hi Marin,

I add the following code to the end of the Main method in my console
applications (sometimes):

if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("Press [enter] to exit");
Console.ReadLine();
}
 
Which, incidentally, answers somebody else's kind of nebulous question about
"How can I tell if my program is running in debug mode".
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Dave Sexton said:
Hi Marin,

I add the following code to the end of the Main method in my console
applications (sometimes):

if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("Press [enter] to exit");
Console.ReadLine();
}

--
Dave Sexton

Marin said:
Right now my solution to this is adding Console.ReadLine at the end but
I'm
wondering if it's possible to do it automatically?

If I chose "Start without debug" it does just that, it pauses right before
the console window closes, but "Start with debug" closes the window right
away.
 
Hi Peter,

Possibly :)

--
Dave Sexton

Peter Bromberg said:
Which, incidentally, answers somebody else's kind of nebulous question
about
"How can I tell if my program is running in debug mode".
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Dave Sexton said:
Hi Marin,

I add the following code to the end of the Main method in my console
applications (sometimes):

if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("Press [enter] to exit");
Console.ReadLine();
}

--
Dave Sexton

Marin said:
Right now my solution to this is adding Console.ReadLine at the end but
I'm
wondering if it's possible to do it automatically?

If I chose "Start without debug" it does just that, it pauses right
before
the console window closes, but "Start with debug" closes the window
right
away.
 
Back
Top