473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to handle Ctrl-C event on a multi-threaded console application?

Hi All

I'm using SetConsoleCtrlH andler to handle Ctrl-C event. But I have a
problem using it in multi-threaded applications (it doesn't invoke
handler function).

What is the correct way to handle Ctrl-C event in a multi-threaded
application??
Basel

May 29 '06 #1
3 5857
On 29 May 2006 05:08:09 -0700, "Basel" <ba****@gmail.c om> wrote:
Hi All

I'm using SetConsoleCtrlH andler to handle Ctrl-C event. But I have a
problem using it in multi-threaded applications (it doesn't invoke
handler function).

What is the correct way to handle Ctrl-C event in a multi-threaded
application? ?
Basel


try
http://www.gotdotnet.com/community/u...3-b4fd97f9825e

--
Ludwig Stuyck
http://www.coders-lab.be
May 29 '06 #2
This sample works fine for single thread applications.
but it doesn't work for multi-threaded applications.

Basel

May 29 '06 #3
On 29 May 2006 05:24:23 -0700, "Basel" <ba****@gmail.c om> wrote:
This sample works fine for single thread applications.
but it doesn't work for multi-threaded applications.

Basel


Also if you handle the event in every thread?
(see last remark on that page: My 2-cents. My experience with this is
that in a multi-threaded console application you MUST handle the event
in each working thread to capture reliably.)
--
Ludwig Stuyck
http://www.coders-lab.be
May 29 '06 #4

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

Similar topics

8
12174
by: Mike Maxwell | last post by:
<vent> I see there has been traffic over the years on this gripe, so just let me vent my frustration, and add another reason why 'exit' (or possibly exit() or quit() or halt() or some such) should exit Python, rather than giving the ridiculous msg Use Ctrl-D (i.e. EOF) to exit. The additional reason is that God intended Ctrl-D to be "scroll down", as in vi. I have my keyboard translator set up to do something very much like that...
4
13969
by: Scott | last post by:
I am using a TCPIP connection to communicate over port 23 (telnet) to a server, and I am having to mimic normal command line interface you owuld see in a telnet session (i.e. I have to write to this socket just like you would enter things on the keyboard if you telneted to this server). In a normal telnet session you can enter some commands which take a long time to complete, and they run in the background and you get the command line...
4
35490
by: Fred Heida | last post by:
Hi All, maybe this is a sill question..but if i have TextBox and use the SendMessage(..) to send a character the control.. the KeyDown event is not triggered.... in would need to check in the WndProc(...) of the WM_CHAR event... Is there another way to send characters to the TextBox, when I'm only having the control's handle which does simulated the user typing in characters so the KeyDown event gets
3
4956
by: Greg | last post by:
I want to be able to capture the user pressing Ctrl+S. I know that the IE browser has a key binding for Ctrl+S but is there any way that I can be notified of this key press anyway. I have found tons of examples of capturing keys in IE but *none* of them work for capturing Ctrl+S, Ctrl+F, Ctrl+P,etc or any key combination that has a binding in IE. Does anyone know how to do this?
3
7103
by: Glen Hong | last post by:
I have set up a hotkey using RegisterHotKey API function for Ctrl-Tab. Firstly, I can rap this when Ctrl-Tab is pressed however if I want to add an addition hotkey how can I distinguish between which hotkey was pressed? Secondly I am trying to replicate the Ctrl-Tab functionality you have in the DotNet IDE when you hold down the Ctrl key and then additional use the tab key you can cycle thru the MDI Children. I would like to gain the...
2
2872
by: crjunk | last post by:
I'm trying to write a piece of code that will programatically save a record automatically without me having to add a new ' Row.Item("ADD1") = txtAdd1.Text.Trim.ToUpper ' type command each time I add a new textbox. I've named all my textboxes in the following format txtAdd1 and I've named all my field in the SQL table the same way minus the txt at the beginning. This code scans the form for textboxes. If it finds a text box that is not...
1
2597
by: psawant | last post by:
Hi! I want to handle "kill","ctrl-c" sigkill,sigint signals in vb.net. I have done it once in C. It was a cake wake.Could not a figure out how to do the same in vb.net. Thanks all.. In advance.
2
8639
by: s99999999s2003 | last post by:
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some other subprocess modules) and how can i pass Ctrl-C to this program to terminate it in python? thanks
11
2246
by: Bookham Measures | last post by:
Hello As above, my Ctrl + Spacebar for intellisense is not working in VI 6.0. I have checked keyboard assignments and Ctrl + Space is listed for Edit -> CompleteWord. I added Ctrl + Shift + Space and that does work, but Ctrl + Space does not. I removed Ctrl + Space thinking re-adding it might help, but now the
7
175
by: Lie Ryan | last post by:
>>I want to write something that handle every char immediately after its Don't you think that getting a one-character from console is something that many people do very often? Do you think that all these platform independent code should be moved to the interpreter level instead (and raises the appropriate error when the platform somehow cannot do unbuffered input)? So python developer could do something like this: raw_input(bufferring...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.