PC Review


Reply
Thread Tools Rate Thread

Console.Writeline hangs if user click into the console window

 
 
Urs Eichmann
Guest
Posts: n/a
 
      16th Jul 2004
I have a console app which does it's job and frequently spits out status
messages with Console.Writeline. I noticed that, if the user
accidentally clicks into the black console window, the cursor changes to
a filled white rectangle, and the app hangs at the next Console.Write
statement.

Can that be solved somehow? It is very dangerous for the application to
stop just because of a wrong mouse click.

I know I could reimplement the app as a windows forms app and write the
status messages to a ListView - but it is more of a fundamental
question. Since if this cannot be solved, I'd never write another
console app again for production environments.

Thanks for any help
Urs
 
Reply With Quote
 
 
 
 
Gary Chang
Guest
Posts: n/a
 
      17th Jul 2004
Hi Urs,

> Can that be solved somehow? It is very dangerous for the application to
> stop just because of a wrong mouse click.


It is a generic feature of the Console window when its "QuickEdit Mode"(
"...\ConsoleApp.exe" Properties\Options\Edit Options) is enabled, in order
to disable that feature, you should uncheck the "QuickEdit Mode" option of
your app's console window at run-time by code:
...
Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Integer)
As Integer
Declare Function GetConsoleMode Lib "kernel32" (ByVal hConsoleHandle As
Integer, ByRef lpMode As Integer) As Integer
Declare Function SetConsoleMode Lib "kernel32" (ByVal hConsoleHandle As
Integer, ByVal dwMode As Integer) As Integer

Public Const STD_INPUT_HANDLE = -10&
...
Dim hConsole As Integer
Dim iMode As Integer
Dim bSuccess As Integer

hConsole = GetStdHandle(STD_INPUT_HANDLE)
'bSuccess = GetConsoleMode(hConsole, iMode)
iMode = &HB7 ' Note below
bSuccess = SetConsoleMode(hConsole, iMode)
...

Note: the &HB7 is the console's mode value when disabled "QuickEdit Mode"
on my machine, if it is different with yours, please uncomment the previous
code line('bSuccess = GetConsoleMode...), and set a BreakPoint on that
line, then at the run-time when the program stops here, right click the
titlebar of the program's console window, select "Properties" and in its
"Options" tab, uncheck the "QuickEdit Mode" item, then click OK(select
"Apply properties to current window only"). Now return to the debugger,
step run the GetConsoleMode(hConsole, iMode) code and recode iMode value it
got, then stop debugging and replace that &HB7 with the new recorded iMode
value...


Wish it helps!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

 
Reply With Quote
 
Urs Eichmann
Guest
Posts: n/a
 
      19th Jul 2004
Thanks it worked, with the &HB7 value. But I wonder, can this value be
differnt on a customer's machine? If yes, is there any possibliblity to
get this value at runtime?


Gary Chang wrote:
> Hi Urs,
>
>
>>Can that be solved somehow? It is very dangerous for the application to
>>stop just because of a wrong mouse click.

>
>
> It is a generic feature of the Console window when its "QuickEdit Mode"(
> "...\ConsoleApp.exe" Properties\Options\Edit Options) is enabled, in order
> to disable that feature, you should uncheck the "QuickEdit Mode" option of
> your app's console window at run-time by code:
> ..
> Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Integer)
> As Integer
> Declare Function GetConsoleMode Lib "kernel32" (ByVal hConsoleHandle As
> Integer, ByRef lpMode As Integer) As Integer
> Declare Function SetConsoleMode Lib "kernel32" (ByVal hConsoleHandle As
> Integer, ByVal dwMode As Integer) As Integer
>
> Public Const STD_INPUT_HANDLE = -10&
> ..
> Dim hConsole As Integer
> Dim iMode As Integer
> Dim bSuccess As Integer
>
> hConsole = GetStdHandle(STD_INPUT_HANDLE)
> 'bSuccess = GetConsoleMode(hConsole, iMode)
> iMode = &HB7 ' Note below
> bSuccess = SetConsoleMode(hConsole, iMode)
> ..
>
> Note: the &HB7 is the console's mode value when disabled "QuickEdit Mode"
> on my machine, if it is different with yours, please uncomment the previous
> code line('bSuccess = GetConsoleMode...), and set a BreakPoint on that
> line, then at the run-time when the program stops here, right click the
> titlebar of the program's console window, select "Properties" and in its
> "Options" tab, uncheck the "QuickEdit Mode" item, then click OK(select
> "Apply properties to current window only"). Now return to the debugger,
> step run the GetConsoleMode(hConsole, iMode) code and recode iMode value it
> got, then stop debugging and replace that &HB7 with the new recorded iMode
> value...
>
>
> Wish it helps!
>
> Best regards,
>
> Gary Chang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
> --------------------
>

 
Reply With Quote
 
Gary Chang
Guest
Posts: n/a
 
      20th Jul 2004
Hi Urs,

I think that value should be unique in most Windows platform.


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

 
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
Why Does Console.WriteLine() Not Write to Command Window? joey.powell@topscene.com Microsoft C# .NET 6 4th May 2007 07:05 AM
Console.WriteLine vs. Debug.WriteLine formatting Zytan Microsoft C# .NET 1 27th Feb 2007 02:24 AM
Why Won't This Console App Do A Console.WriteLine() ? jabailo@texeme.com Microsoft Dot NET 4 24th Jun 2005 02:09 AM
Why Won't This Console App Do A Console.WriteLine() ? jabailo@texeme.com Microsoft C# .NET 2 21st Jun 2005 06:09 AM
Console.Writeline() hangs IDE? Bob Microsoft VB .NET 4 3rd Feb 2004 05:07 PM


Features
 

Advertising
 

Newsgroups
 


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