有谁有一个关于如何使用 Synapse 的 Heartbeat 功能的好例子吗?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管我建议在单独的线程中运行下载,但阅读文档后,您必须将事件处理程序挂钩到 OnHeartBeat 事件。
在该事件处理程序中,您可以调用
Application.ProcessMessages()
但这很危险,因为事件可能在您真正需要它们之前就被触发了。我将使用自定义方法仅调用 Paint 例程。您可以将表单的句柄作为参数传递,或者将任何控件转换为 TWinControl 并使用句柄属性。这只会重新绘制表单/控件,但不允许鼠标/键盘交互。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.