Éric Fleming Bonilha wrote: > So, one doubt that I have is, if I´m using a thread to process the > socket > messages using the MessageLoop procedure, all the TWSocket events like > OnSessionConnected and OnDataAvailable is triggered using the thread > context, right? So, my handle for those events should be working on > the > thread context?
To make sure the events are triggered in worker thread context you must either create the TWSocket instance from worker thread's Execute method (suggested) or use methods ThreadDetach and ThreadAttach. To realize a poll in intervals you could write a message loop in Execute by the help of Windows function MsgWaitForMultipleObjects(). Does this answer your question, I'm not sure whether I understood it correctly? For instance the Excecute method may look something like below. CurTimeOut := 10000; StartTicks := GetTickCount; while not Terminated do begin Res := MsgWaitForMultipleObjects(0, Dummy, False, CurTimeOut, QS_POSTMESSAGE or QS_SENDMESSAGE); // if there is one or more messages in the queue ... if Res = (WAIT_OBJECT_0 + 0) then begin while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do begin case Msg.message of WM_QUIT : begin Terminate; Break; end; {more, user defined messages here} [..] else TranslateMessage(Msg); DispatchMessage(Msg); end; end; { Recalculate Timeout } CurTicksAppart := CalcTicksAppart(StartTicks, GetTickCount); if CurTicksAppart >= CurTimeOut then begin if not Terminated then DoSomething; StartTicks := GetTickCount; CurTimeOut := 10000; end else Dec(CurTimeout, CurTicksAppart); end else if Res = WAIT_TIMEOUT then begin if not Terminated then DoSomething; StartTicks := GetTickCount; CurTimeOut := 10000; end end; > > ----- Original Message ----- > From: "Arno Garrels" <[EMAIL PROTECTED]> > To: "ICS support mailing" <twsocket@elists.org> > Sent: Monday, August 07, 2006 11:01 AM > Subject: Re: [twsocket] Multithreaded Client Application > > > Éric Fleming Bonilha wrote: >> Hello, >> >> I´m writing a multi-threaded client application >> >> I read the ICS code and there is written that to make a real multi- >> threaded application we should do ThreadAttach and use the >> messageloop procedure on the execute method of the working thread. >> I´m doing this, but, how do I stop this thread? How can I exit from >> the loop to free the thread? There is written that the message >> WM_QUIT should be sent, but to what handler? > > First of all, you don't need multi-threading by default for the socket > I/O. ICS uses asynchron winsock API. If you want to process lengthy > tasks the you should move that stuff in a workerthread and send the > result when the thread finished. > >> There is written that the message >> WM_QUIT should be sent, but to what handler? > > The message loop stopps, means function GetMessage() returns FALSE > when it receives a WM_QUIT message. If yuo use TWSocket.MessageLoop > you need to send it to the window handle (property Handle) of TWsocket > (or property CtrlSocket). > > --- > Arno Garrels [TeamICS] > http://www.overbyte.be/eng/overbyte/teamics.html > > > > > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be