Console.WriteLine

  • Thread starter Thread starter AA2e72E
  • Start date Start date
A

AA2e72E

If I am stepping through the code using F11, how can I leave the Console
'window' remain open/visible after a Console.WriteLine statement?

Thanks.
 
AA2e72E said:
If I am stepping through the code using F11, how can I leave the Console
'window' remain open/visible after a Console.WriteLine statement?

Do not maximize the Visual Studio window. Rearrange the windows on your
desktop so that Visual Studio and the Console window are shown side-by-side.
In this way you can press F11 on Visual Studio at the same time that you can
see what is being displayed in the Console that is shown on one side.
 
Thanks Alberto; that works but does not give me quite what I want.

I was hoping for some configuration option to 'force' the window to stay
open e.g. when you Ctrl + F5, there is a prompt to close the window.

I am JIT compiling code i.e. working outside VS & would like to find some
way of maintaining the Window when the JIT code runs.

I tried Console.ReadKey() as a means of halting the code & expecting me to
[ress a key but that does not seem to work.
 
Hello,

Console.ReadKey should definitely work.

What if you try :

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to end...");
Console.ReadKey();
}
}


For now my understanding is that you have a console application and that at
the end of the program you want to keep the window open until the user
presses a key.

As Alberto I found for now your question quite confusing (seems unrelated
with stepping throught code with F11 or the JIT compiler). Note thought that
Console.ReadKey gives focus to the console window so pressing F11 again will
be taken as an input so you'll run the whole code includign terminating the
program if you just keep pressing F11. Could it be what you experience ?..


--
Patrice



AA2e72E said:
Thanks Alberto; that works but does not give me quite what I want.

I was hoping for some configuration option to 'force' the window to stay
open e.g. when you Ctrl + F5, there is a prompt to close the window.

I am JIT compiling code i.e. working outside VS & would like to find some
way of maintaining the Window when the JIT code runs.

I tried Console.ReadKey() as a means of halting the code & expecting me to
[ress a key but that does not seem to work.


Alberto Poblacion said:
Do not maximize the Visual Studio window. Rearrange the windows on
your
desktop so that Visual Studio and the Console window are shown
side-by-side.
In this way you can press F11 on Visual Studio at the same time that you
can
see what is being displayed in the Console that is shown on one side.

.
 
Hi Patrice,
As I said in my previoud post:

- Alberto's suggestion does work
- I have already tried Console.ReakKey() and it does not keep the window open

It is possible that F11 triggers F11 as the completion of Console.ReakKey().

I have a code snippet: it is the same as in a Console Application and I am
compiling it using JIT. My original intention was to find some way of
ensuring the same behaviour as Ctrl+F5 in a console application both from a
console application and Jit compiled code. So far, I can use Alberto's
suggestion with console application and I am still searching for a way to
prevent the window from closing with the Jit code.....

Patrice said:
Hello,

Console.ReadKey should definitely work.

What if you try :

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to end...");
Console.ReadKey();
}
}


For now my understanding is that you have a console application and that at
the end of the program you want to keep the window open until the user
presses a key.

As Alberto I found for now your question quite confusing (seems unrelated
with stepping throught code with F11 or the JIT compiler). Note thought that
Console.ReadKey gives focus to the console window so pressing F11 again will
be taken as an input so you'll run the whole code includign terminating the
program if you just keep pressing F11. Could it be what you experience ?..


--
Patrice



AA2e72E said:
Thanks Alberto; that works but does not give me quite what I want.

I was hoping for some configuration option to 'force' the window to stay
open e.g. when you Ctrl + F5, there is a prompt to close the window.

I am JIT compiling code i.e. working outside VS & would like to find some
way of maintaining the Window when the JIT code runs.

I tried Console.ReadKey() as a means of halting the code & expecting me to
[ress a key but that does not seem to work.


Alberto Poblacion said:
If I am stepping through the code using F11, how can I leave the
Console
'window' remain open/visible after a Console.WriteLine statement?

Do not maximize the Visual Studio window. Rearrange the windows on
your
desktop so that Visual Studio and the Console window are shown
side-by-side.
In this way you can press F11 on Visual Studio at the same time that you
can
see what is being displayed in the Console that is shown on one side.

.

.
 
AA2e72E said:
Hi Patrice,
As I said in my previoud post:

- Alberto's suggestion does work
- I have already tried Console.ReakKey() and it does not keep the window open

It is possible that F11 triggers F11 as the completion of Console.ReakKey().

Are you sure Visual Studio is the active window when you're tapping the
F11 key?
 
- I have already tried Console.ReakKey() and it does not keep the window

Works here...
My original intention was to find some way of
ensuring the same behaviour as Ctrl+F5 in a console application both from
a
console application and Jit compiled code.

IMO the behavior you see is a VS features i.e.it is likely thet before
terminating a console application VS automatically asks the user to press a
key in the console.

So using Console.ReadKey() have to be placed inside your code so that you
still have this behavior when running directtly the EXE file.
 
AA2e72E said:
Hi Patrice,
As I said in my previoud post:

- Alberto's suggestion does work
- I have already tried Console.ReakKey() and it does not keep the window open

It is possible that F11 triggers F11 as the completion of Console.ReakKey().

I have a code snippet: it is the same as in a Console Application and I am
compiling it using JIT. My original intention was to find some way of
ensuring the same behaviour as Ctrl+F5 in a console application both from a
console application and Jit compiled code. So far, I can use Alberto's
suggestion with console application and I am still searching for a way to
prevent the window from closing with the Jit code.....

"Patrice" wrote:

I don't know what you are doing, but I'm pretty sure that it's not what
you are saying that you are doing... ;)

It seems that you are confused about the JIT compiler. The JIT compiler
is not an alternative to how code is executed normally, it *is* the way
that code is executed normally. It's the JIT compiler that creates the
executable code from the IL code that the C# compiler produces. JIT
stands for Just In Time, because the compiler does it's work just before
the code is executed.

If you mean that you compile the code into a native executable, that is
not done by the JIT compiler, that is done by a tool like Ngen.

If you mean that you are compiling the code manually outside Visual
Studio, the compilation process is still the same.

-

If you want to do something like the Visual Studio environment does, but
not as sensetive as to trigger on your F11 keypresses, perhaps you
should wait for a specific key:

Console.WriteLine("Press Esc to quit.");
while (Console.ReadKey(true).Key != ConsoleKey.Escape) { }
 
Waiting for a specific key seems to be the answer, as you've suggested.
Thanks.

I am confused by others being confused.

I have a piece of code.

a. I can step through it in VS2008 using F11: the window does not wait to
close as it would do had I run the code using Ctrl + F5. Here, Alberto's
suggestion let's me see the Window when using F11.

b. Alternatively, I can (programatically) submit the same code to an
assembly that compiles it and runs it i.e working completely outside VS2008.
Here, the window hardly appears, let alone stay visible. I can see the result
by writing it to a file.

My quest was this: Is there some way of keeping the window open and I tried
Console.ReadKey() and that did not work. I wondered whether there was some
configuration setting to get the Ctrl +F5 behaviour in scenario b above.

It appears not!

However, waiting for a specific key does provide an excellent work around.

Thank you for your help, everyone.
 
Back
Top