473,232 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

Console.Writeline hangs if user click into the console window

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
Nov 20 '05 #1
3 9203
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.
--------------------

Nov 20 '05 #2
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.
--------------------

Nov 20 '05 #3
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.
--------------------

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
1
by: Mullin Yu | last post by:
But, I want is that I can have a Main app that will start a new process or kill one particular or all process. The process will open a console exe. But, I don't want the user to close the console...
5
by: Publicjoe | last post by:
I am working on a little app which uses colour in the console window. I have created a class to extend the console functionality but the ClearScreen method does not work correctly. I am enclosing a...
17
by: MumboJumbo | last post by:
Hi I have a really basic question hopefully some can help me with: Can you write a (i.e. one) C# project that works from the cmd line and gui? I seems if i write a GUI app it can't write to...
12
by: Jarod_24 | last post by:
I got a project called "Forms" that hold some forms and stuff in my solution. A argument at startup defines wether to use a From or Console. My plan was to create a myConsole class that would...
4
by: Bob | last post by:
I just recently noticed that when I start my applicatoin in debug mode, the IDE hangs (no disk or CPU activity) indefinitely (at least 20 minutes). Pausing the application shows that it's hung up...
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
12
by: Dilip | last post by:
Hi All I have a server based C# console application. This application must hide its console window when its launched out on the field. So I dutifully P/Invoke'd FindWindow/ShowWindow...
0
by: Stephen Thomas | last post by:
Hi there I wonder if any one has encountered this problem or can suggest what is wrong. I am trying the a procedure from the msn site but get the following message: Error 1 The type or...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.