Pausing the console program before it returns

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.
 
M

Michael A. Covington

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.
 
L

Lucian Wischik

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.
 
D

Dave Sexton

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();
}
 
G

Guest

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.
 
D

Dave Sexton

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top