I have an application that is sending/receiving data over a Windows socket. I want to know how to interupt this process when the user clicks the Cancel button on my Dialog.
Is there something like a Windows ProcessMessages function?
I connect to a remote device and begin sending data in a while loop. I want the user to be able to interrupt this while loop by clicking a Cancel button in the Dialog box. Currently the while loop continues until it finishes and all of the Dialog functions are disabled (not handled) until the loop finishes. I don't want to return from the function unless the button is actually clicked.
In this case, the cancel clicking of the user should send some specific data. By parsing this data, your program should decide, is it data for closing or for workning forward. John Fill
The Cancel button is on the Client side of the communication.
The client clicks Connect and starts sending data, then say he wants to click Cancel to interrupt the process. Currently the client application is busy sending data. There is no user on the other side of the connection.
I think there should a separate thread what reads, does the user want to cancel or not. In the client side also should be a separate thread what send the user's wishes, to cancel or not to cancel. By the way, DCOM has every you want. There you don't need to invent some new, just implement existent interfaces. John Fill
I think there are many solutions for your problem:
1. As JohnFill says you make a separate thread for the window in witch you have the cCancel Button, and on cancel event you can do this:
* make a SetEvent call to announce tha main thread that cancel was pressed.
* in the Send loop of the main program (of your socket class), you should verify the state of this event. if it is Signaled you should call Abort or cancel in other way the sending of the data (I suppose you make it through packets).
Hope of being of some help, s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
Just to let you know the function is called PeekMessage, which stops and looks at the current queue of Windows messages and processes any that it finds. I put this inside my loop so it is constantly looking for the Cancel button to be pressed while it communicates with the remote device.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.