gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:20:23 26 4
gpt4 key购买 nike

我在 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 时单击客户端应用程序上的任意位置会使该应用程序看起来像是挂起的(标题栏中出现“未响应”)。

我认为最好的解决方案是将 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 线程以外的线程中运行长时间运行的查询。

关于delphi - 在等待 DataSnap 时更新客户端 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9523543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com