我在Delphi XE2中创建了一个MDI Delphi应用程序,它通过TSQLConnection组件(driver = datasnap)连接到DataSnap服务器.在设计时右键单击TSQLConnection可以生成DataSnap客户端类(ProxyMethods).
我的目标是在客户端有一个经过时间的时钟[0:00],显示DataSnap请求服务的时间,每1秒更新一次.我尝试过但不起作用的两种方法是:
方法#1
Use a TTimer
with a 1 second interval that updates the elapsed time clock while a ProxyMethod is being execute. I enable the timer just before calling the ProxyMethod. While the ProxyMethod is running,the OnTimer
event doesn’t fire — a breakpoint in the code is never hit.
方法#2
Same as Method #1,except the timer is a TJvThreadTimer
. While the ProxyMethod is running,the OnTimer
event fires,but the OnTimer
code doesn’t get execute until after the ProxyMethod completes. This is evident because a breakpoint in the OnEvent
code gets hit in rapid succession after the ProxyMethod completes — like the OnTimer
events have all been queued in the main VCL thread.
此外,在慢速ProxyMethod运行时单击客户端应用程序上的任何位置会使应用程序显示为挂起(标题栏中显示“Not Responding”).
我认为最好的解决方案是将ProxyMethods的执行移动到一个单独的线程.但是,必须有一个现有的解决方案 – 因为相关的挂起应用程序问题似乎是一个常见的抱怨.我只是找不到解决方案.
任何建议表示赞赏.否则,我将辞职,将ProxyMethod执行移动到一个单独的线程中.
您已经确定了根本问题.您的查询正在UI线程中运行,并在运行时阻止该线程.不会发生UI更新,计时器消息无法触发等.
I think the best solution is to move the execution of the ProxyMethods to a separate thread. However,there must be an existing solution — because the related hung app issue seems like it would be a common complaint. I just can’t find the solution.
您已经找到了解决问题的唯一方法.您必须在UI线程以外的线程中运行长时间运行的查询.