有谁有一个关于如何使用 Synapse 的 Heartbeat 功能的好例子吗?

发布于 2024-08-13 06:03:03 字数 390 浏览 11 评论 0原文

我正在使用 Synapse for Delphi,但是在 HTTP 下载期间,GUI 当然会冻结。查看文档,他们建议使用 OnHeartbeat 方法。

(参见http://www.ararat.cz/synapse/doku。 php/public:howto:heartbeat

不幸的是,他们实际上没有给出任何代码示例,虽然概念很简单,但用法并不明显。

这是每个套接字(对象)设置,还是每个应用程序(类)设置?另外,回调过程本身被定义为一个对象,这有点不寻常。有真正使用过这个的人愿意分享示例代码片段吗?

I am using Synapse for Delphi, but when during HTTP downloads, of course, the GUI freezes. Looking at the documentation, they suggest using the OnHeartbeat method.

(See http://www.ararat.cz/synapse/doku.php/public:howto:heartbeat )

Unfortunately, they don't actually give any code example, and while the concept is simple, the usage is non-obvious.

Is this a per socket (object) setting, or a per application (class) setting? Also, The callback procedure itself is defined as an object, which is a bit unusual. Is anyone who has actually used this willing to share a sample code snippit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

快乐很简单 2024-08-20 06:03:03

尽管我建议在单独的线程中运行下载,但阅读文档后,您必须将事件处理程序挂钩到 OnHeartBeat 事件。

在该事件处理程序中,您可以调用 Application.ProcessMessages() 但这很危险,因为事件可能在您真正需要它们之前就被触发了。我将使用自定义方法仅调用 Paint 例程。您可以将表单的句柄作为参数传递,或者将任何控件转换为 TWinControl 并使用句柄属性。这只会重新绘制表单/控件,但不允许鼠标/键盘交互。

procedure AllowRepaints(h: HWND);
var
  m: tMsg;
begin
  while PeekMessage(m, h, WM_PAINT, WM_PAINT, PM_REMOVE) do
    DispatchMessage(m);
end;

Although I would suggest running your download in a seperate thread, reading the documentation you'd have to hook a event handler to the OnHeartBeat event.

In that event handler, you could call Application.ProcessMessages() but that is just dangerous due to the possibility of events being fired before you'd actually want them. I would use a custom method to invoke the Paint routine only. You could just pass the handle of your form as parameter, or cast any control to a TWinControl and use the handle property. This will just repaint the form/control, but not allow mouse/keyboard interaction.

procedure AllowRepaints(h: HWND);
var
  m: tMsg;
begin
  while PeekMessage(m, h, WM_PAINT, WM_PAINT, PM_REMOVE) do
    DispatchMessage(m);
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文