在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
通过postmessage同步线程的方法。 原帖地址:http://blog.csdn.net/jfyes/archive/2007/01/18/1487057.aspx 呵呵,N久前的问题现在忘记了,搞得我找了一个小时的原因才找出是线程里面更
1const
2 WM_THREAD_MSG = WM_USER + $FF; 3 4procedure WMThread_msg(var Msg: TMessage); message WM_THREAD_MSG; 5 6type 7 TDataPack = record 8 ID: WORD; 9 DataSize: Integer; 10 Data: PChar; 11 end; 12 PDataPack = TDataPack 13 14procedure TDataPack.Execute; 15var 16 AData: TDataPack; 17begin 18 inherited; 19 FBindIndex := socket_state; 20 while (not self.Terminated) and (FBindIndex > -1)do 21 begin 22 try 23 //Synchronize(SynchronizeMethod); //线程同步 24 FillChar(AData, SizeOf(AData), #0); 25 if ReadSocket(FSocket[FBindIndex], AData) then 26 PostMessage(Application.MainForm.Handle, WM_THREAD_MSG, 0, Longint(@PDataPack)); 27 28 Sleep(FWaitTime); 29 except on E: Exception do 30 WriteLog(g_ProLogFile, E.Message); 31 end; 32 end; 33 34end; 35procedure TMainForm.WMThread_msg(var Msg: TMessage); 36var 37 Data: PDataPack; 38begin 39 Data := PDataPack(Msg.lParam); 40 if Data <> nil then 41 begin 42 //TODO: 处理数据 43 end; 44end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论