Hello Wayne,

Make sure you do not call WSocket->Handle after you threaddetach. This
call would auto-threasdattach!!

Regards,

SZ

On 5/29/09, wayne forrest <wayneforr...@gmail.com> wrote:
> I am having a problem that I do not understand, what It means,
>
> The Error message I receive is: *'Cannot detach from another thread'*
>
> Here is my code, based on some example I got from ICS, the code below is in
> my Main Unit.
>
>
> {*
>  We have to attach client socket to this thread's context and then
>  process messages so that TWSocket events works.
> }
> procedure TClientThread.Execute;
> begin
>    if not Assigned(WSocket) then
>        Exit;
>
>    { Attach client socket to this thread
> }
>    WSocket.ThreadAttach;
>    { Signal main thread that we've attached socket to this thread
> }
>    ThreadAttached := TRUE;
>    { Now let main thread continue starting the connection.
> }
>    { This little avoid race condition.
> }
>    Sleep(0);
>    { Let's block on critical section already owned by main thread
> }
>    EnterCriticalSection(FCritSect);
>    LeaveCriticalSection(FCritSect);
>    { Then process messages until WM_QUIT message is posted.
> }
>    { TWSocket is event-driven. So even when used within a thread, we
> }
>    { have to have a "message pump". Any message pump will do and there
> }
>    { is one built in TWSocket, so use it !
> }
>    WSocket.MessageLoop;
>    { Be sure to have main thread waiting for termination before
> terminating}
>    Sleep(0);
>    { Detach the hidden window from within the thread
> }
>    WSocket.ThreadDetach; //<<<<<<< ERROR Event Raised.
> end;
>
> --
> C: 076 337 4368
> T: 021 880 2037
> F: 021 880 2530
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to