PC Review


Reply
Thread Tools Rate Thread

Console.WriteLine

 
 
AA2e72E
Guest
Posts: n/a
 
      7th Feb 2010
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.
 
Reply With Quote
 
 
 
 
Alberto Poblacion
Guest
Posts: n/a
 
      7th Feb 2010
"AA2e72E" <(E-Mail Removed)> wrote in message
news:6FF1FDB3-1606-44C9-B813-(E-Mail Removed)...
> 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.

 
Reply With Quote
 
AA2e72E
Guest
Posts: n/a
 
      7th Feb 2010
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" wrote:

> "AA2e72E" <(E-Mail Removed)> wrote in message
> news:6FF1FDB3-1606-44C9-B813-(E-Mail Removed)...
> > 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.
>
> .
>

 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      7th Feb 2010
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" <(E-Mail Removed)> a écrit dans le message de
news5E24482-FF6F-4FC8-BEDE-(E-Mail Removed)...
> 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" wrote:
>
>> "AA2e72E" <(E-Mail Removed)> wrote in message
>> news:6FF1FDB3-1606-44C9-B813-(E-Mail Removed)...
>> > 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.
>>
>> .
>>


 
Reply With Quote
 
AA2e72E
Guest
Posts: n/a
 
      7th Feb 2010
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:

> 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" <(E-Mail Removed)> a écrit dans le message de
> news5E24482-FF6F-4FC8-BEDE-(E-Mail Removed)...
> > 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" wrote:
> >
> >> "AA2e72E" <(E-Mail Removed)> wrote in message
> >> news:6FF1FDB3-1606-44C9-B813-(E-Mail Removed)...
> >> > 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.
> >>
> >> .
> >>

>
> .
>

 
Reply With Quote
 
Harlan Messinger
Guest
Posts: n/a
 
      7th Feb 2010
AA2e72E wrote:
> 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?
 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      7th Feb 2010
> - I have already tried Console.ReakKey() and it does not keep the window
> open


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

 
Reply With Quote
 
Göran Andersson
Guest
Posts: n/a
 
      7th Feb 2010
AA2e72E wrote:
> 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) { }

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
AA2e72E
Guest
Posts: n/a
 
      8th Feb 2010
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.


"Göran Andersson" wrote:

> AA2e72E wrote:
> > 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) { }
>
> --
> Göran Andersson
> _____
> http://www.guffa.com
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Console.Writeline shapper Microsoft ASP .NET 4 22nd Sep 2007 03:30 PM
Console.WriteLine vs. Debug.WriteLine formatting Zytan Microsoft C# .NET 1 27th Feb 2007 02:24 AM
Console::WriteLine() bill Microsoft Dot NET Framework Forms 3 24th Dec 2005 12:29 AM
Console.WriteLine Rick Microsoft C# .NET 2 21st Jul 2005 05:49 AM
Console.Writeline hangs if user click into the console window Urs Eichmann Microsoft VB .NET 3 20th Jul 2004 06:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.