【发布时间】:2012-10-29 04:58:42
【问题描述】:
为了在 tcpserver.onexecute(..) 函数内将处理状态信息写入 GUI,我使用了以下命令序列
ExecuteDUMMYCommand(Global_Send_Record);
BitMap_PaintImageProcess;
TThread.Synchronize(nil, BitMap_PaintImageProcess);
代码在某些机器上运行良好,但在少数机器上却失败了。代码执行在 TThread.Synchronize 命令处停止。我猜在这些机器上,函数调用被困在死锁中 有机会找出背后的真正问题吗?
程序 BitMap_PaintImageProcess ,这里我创建了一个 Bitmap 并做了很多绘画工作,但似乎这段代码从未执行过?
我试图解释很长的代码并减少要点,关键的线程问题隐藏在我的 Bitmapprocessing 类中处理位图的过程中。 这个类是在我的 ServerMainForm 的 GUIProcessing 过程中访问的,它也有 INDY TCP Server 组件。
{--------------- CLASS DEFINITION -----------------------------}
TBitMapProcessingClass = class()
FBitmap : TBitmap;
FList : TListOfSomething;
procedure ProcessTheBitmap(....);
......
(many many functions);
procedure Init;
procedure Free;
Procedure Create;
end;
TMainform = class(TForm)
MyServer : TIdTCPServer;
aBitMaoProcessingClass : TBitMaoProcessingClass;
procedure BitMap_PaintImageProcess;
procedure BitMap_ListProcess;
.....
end;
{------------------------- Implemantation ------------------------------}
procedure TMainform.IndyTCPServer.Onexecute()
begin
.......
ExecuteDUMMYCommand(Global_Send_Record);
BitMap_PaintImageProcess;
TThread.Synchronize(nil, BitMap_PaintImageProcess);
.......
end;
procedure TMainform.BitMap_PaintImageProcess;
begin
DoSomeServerVCLStuff(....);
aBitMapProcessingClass.ProcessTheBitmap;
DoSomeServerVCLStuff(....);
end;
【问题讨论】:
-
欢迎来到 StackOverflow。当您在此处发布问题时,请不要大喊大叫。它使它们更难阅读,并且不会更快地为您提供帮助。对你寻求帮助的人大喊大叫也是相当不礼貌的。 ;-) 请不要将标签信息放在主题行中——这里的标签系统运行良好,不需要任何帮助。 :-)
delphi标签清楚地表明您在询问 Delphi,indy标签清楚地表明您的问题是关于 Indy。 -
@KenWhite:在 XE2 TThread 中有一个类过程重载:Synchronize(AThread: TThread; AMethod: TThreadMethod)。如果您将 nil 作为第一个参数传递,则 AMethod 将在主线程中执行:docwiki.embarcadero.com/Libraries/XE2/en/…
-
@iPath:你说的很对;我在发布之前检查了错误版本的 VCL 文档。但是,这并没有解决另一个问题。
-
@user1769184:为什么在 onExecute 中调用 BitMap_PaintImageProcess 然后使用 tthread.synchronize?这是一个错误,还是您使用相同的程序来做真实的事情并进行 GUI 更新?