From: Rohit on
My main thread creates a CAsyncSocket derived class and tries to connect to
the server by calling the Connect method. Unfortunately, since CAsyncSocket
is non-blocking, the OnConnect notification arrives as a message to the main
window. But, I cannot continue processing until a successful connection has
been established and I don't want to create a worker thread to initialize the
socket. Is there any way I can process windows messages and wait until the
OnConnect function returns with the connection status?
From: Scott McPhillips [MVP] on
"Rohit" <Rohit(a)discussions.microsoft.com> wrote in message
news:7287E5A6-A8A6-486D-9A38-57BD0B3FB266(a)microsoft.com...
> My main thread creates a CAsyncSocket derived class and tries to connect
> to
> the server by calling the Connect method. Unfortunately, since
> CAsyncSocket
> is non-blocking, the OnConnect notification arrives as a message to the
> main
> window. But, I cannot continue processing until a successful connection
> has
> been established and I don't want to create a worker thread to initialize
> the
> socket. Is there any way I can process windows messages and wait until
> the
> OnConnect function returns with the connection status?

The way to accomplish this is to "continue processing" when you get the
OnConnect message notification. Returning from the function that calls
Connect will let you process window messages.

If your concern is to prevent user actions until the notification arrives
you can disable the GUI with

AfxGetMainWnd()->EnableWindow(FALSE);

--
Scott McPhillips [VC++ MVP]

From: tanix on
In article <#Oe9SdafKHA.6096(a)TK2MSFTNGP02.phx.gbl>, "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote:
>"Rohit" <Rohit(a)discussions.microsoft.com> wrote in message
>news:7287E5A6-A8A6-486D-9A38-57BD0B3FB266(a)microsoft.com...
>> My main thread creates a CAsyncSocket derived class and tries to connect
>> to
>> the server by calling the Connect method. Unfortunately, since
>> CAsyncSocket
>> is non-blocking, the OnConnect notification arrives as a message to the
>> main
>> window. But, I cannot continue processing until a successful connection
>> has
>> been established and I don't want to create a worker thread to initialize
>> the
>> socket. Is there any way I can process windows messages and wait until
>> the
>> OnConnect function returns with the connection status?
>
>The way to accomplish this is to "continue processing" when you get the
>OnConnect message notification. Returning from the function that calls
>Connect will let you process window messages.
>
>If your concern is to prevent user actions until the notification arrives
>you can disable the GUI with
>
>AfxGetMainWnd()->EnableWindow(FALSE);

Well, thats a flaky idea.
It is probably better to run an async state machine.


--
Programmer's Goldmine collections:
http://preciseinfo.org