应用程序花费很长时间来同步线程(或根本不同步) [英] Application taking a really long time to synch threads ( or not at all )
问题描述
我正在Delphi XE5(iOS和Android)中使用REST组件.我目前正在通过iOS模拟器进行测试,我的应用程序经常挂在代码中的以下行:
I am using REST components in Delphi XE5 (iOS and Android). I am testing via the iOS simulator currently, and my application often hangs at the following line within my code:
R_Request.Execute;
经过一些调试后,我发现它特别挂在REST.Client.PAS中的这一行代码上:
After some debugging, I find it it specifically hangs at this line of code within the REST.Client.PAS:
HandleEvent(DoAfterExecute);
如下所示:
procedure TCustomRESTRequest.HandleEvent(AEventHandler: TMethod);
begin
// Handle Synchronized if we are NOT already in the main thread
// NEVER call synchronize on the MainThread - that might shift the island!
if SynchronizedEvents and (System.MainThreadID <> TThread.CurrentThread.ThreadID) then
TThread.Synchronize(TThread.CurrentThread, AEventHandler) // FAILS HERE
else
AEventHandler;
end;
要么不返回.Synchronize中的线程,要么花费非常长的时间(大约5分钟)... 它在调试时一次起作用,但此后一次又一次(30分钟后,将其设置为5分钟以返回线程).
It's either NOT returning the thread in the .Synchronize or taking an extremely long time ( 5 minutes or so ) ... It worked once while debugging, but has not ever since and again just now ( 30 min later, and after letting it set for 5 minutes to return a thread).
帮助吗?或者至少有人可以给我任何方向感?
Help ? Or at least any sense of direction anyone can give me?
再次,为iOS和Android开发(因此为FMX ...),当前正在通过iOS模拟器进行测试. 谢谢 !
Again, developing for iOS and Android ( so FMX... ) and currently testing via iOS simulator. Thanks !
推荐答案
问题是FireMonkey中的TThread.Synchronize()
已损坏.查看此质量控制报告:
The problem is that TThread.Synchronize()
is broken in FireMonkey. See this QC report:
报告#123579:TThread.Synchronize()和TThread.Queue()在FireMonkey中无法正常工作
这只是最近才被发现,但是自从首次引入FireMonkey以来,它就被破坏了,直到现在为止还没有人注意到.
This has only just recently been discovered, but it has been broken since FireMonkey was first introduced and nobody apparently noticed until now.
直到Embarcadero对其进行修复,然后尝试在主线程中(例如在计时器中)定期调用CheckSynchronize()
.
Until Embarcadero fixes it, try calling CheckSynchronize()
periodically in the main thread, such as in a timer.
这篇关于应用程序花费很长时间来同步线程(或根本不同步)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!