加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 在等待DataSnap时更新客户端UI

发布时间:2020-12-15 09:38:14 所属栏目:大数据 来源:网络整理
导读:我在Delphi XE2中创建了一个MDI Delphi应用程序,它通过TSQLConnection组件(driver = datasnap)连接到DataSnap服务器.在设计时右键单击TSQLConnection可以生成DataSnap客户端类(ProxyMethods). 我的目标是在客户端有一个经过时间的时钟[0:00],显示DataSnap请
我在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线程以外的线程中运行长时间运行的查询.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读