473,386 Members | 1,679 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,386 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 9265
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.