Pause console

  • Thread starter Thread starter kai
  • Start date Start date
K

kai

Hi,
When I use

Console.WriteLine("Hello") in my code, it displays DOS screen so fast,
how do I pause the Console screen?

Thanks

Kai
 
Kai,
The easiest way is to use Console.Read to wait for keyboard input.

Something like:

Public Sub Main()
Console.WriteLine("Hello World")
Console.Read()
End Sub

Of course when you console application runs from the command line, the Read
is not really necessary. It is only needed if your application is run from
Windows Explorer or VS.NET. The February 2004 issue of MSDN Magazine has a
couple of articles that offer some interesting tricks you can do with
Console applications.

Hope this helps
Jay
 
Hi,

In addition to Jay's comments If you start a console app in the ide
by press ctrl+F5 it will keep the console window open until you press any
key.

Ken
 
* "kai said:
Console.WriteLine("Hello") in my code, it displays DOS screen so fast,
how do I pause the Console screen?

There is no DOS screen. It's a Windows console. What exactly do you
mean by "displays DOS screen so fast"? The window will close
automatically if the application runs from the IDE/Windows and not from
a console window. You can use something like that to prevent the window
from closing:

\\\
If #Debug Then
Console.Read()
End If
///
 
Ken,
Cool!

I did not realize that Ctrl+F5, start without debugging, did that!

I can see using Ctrl+F5 and putting a break point on the last statement of
Main, to avoid using the #if Debug method Herfrield showed... (depending on
the app I like the #if debug method also).

Thanks
Jay
 
Back
Top