开发者

TThread Doesn't Do It's Job Unless there is a MessageBox in the Middle !

i created a class of TThread to do some socket operations, the thing is, the code doesnt work unle开发者_如何学Pythonss i add MessageBox to it, sockets wont work unless i put a MessageBox call before it

 Sleep(2000); //Waiting for the Socket to Come to the Array
 // Messagebox(0, '', '', 0); { Wont work unless this line is Uncommented }
 if Server.ClientList[Handle] <> nil then
 begin
  if (Server.ClientList[Handle].Connected) and (AppSocket.Connected) do
  begin
   // Send Data on Socket
   // Relay Data between Server.ClientList[Handle] and AppSocket;
  end; 


Assuming you are using non-blocking sockets, then your thread needs a running message queue and processing loop. That is why calling MessageBox() works - it is a modal dialog that pumps the calling thread's message queue internally. Your thread needs to call PeekMessage() or GetMessage() in a loop for the lifetime of the connection(s). Your loop can use MsgWaitForMultipleObjects() to detect when the message queue has something to process, if your thread has other things it needs to do.


Try to replace Messagebox() with Application.ProcessMessages and see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜