在 Delphi 中,TDataSet 线程安全吗?

编程入门 行业动态 更新时间:2024-10-22 18:33:48
本文介绍了在 Delphi 中,TDataSet 线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望能够在它自己的线程中异步打开一个 TDataSet,以便主 VCL 线程可以继续运行直到完成,然后让主 VCL 线程从该 TDataSet 中读取.我做了一些实验,遇到了一些非常奇怪的情况,所以我想知道以前是否有人这样做过.

I'd like to be able to open a TDataSet asynchronously in its own thread so that the main VCL thread can continue until that's done, and then have the main VCL thread read from that TDataSet afterwards. I've done some experimenting and have gotten into some very weird situations, so I'm wondering if anyone has done this before.

我见过一些示例应用程序,其中 TDataSet 在单独的线程中创建,它被打开,然后从中读取数据,但这一切都是在单独的线程中完成的.我想知道在另一个线程打开数据源之后从主 VCL 线程中读取 TDataSet 是否安全.

I've seen some sample apps where a TDataSet is created in a separate thread, it's opened and then data is read from it, but that's all done in the separate thread. I'm wondering if it's safe to read from the TDataSet from the main VCL thread after the other thread opens the data source.

我正在 Delphi 7 中进行 Win32 编程,使用 DAC for MySQL 作为我的 TDataSet 后代.

I'm doing Win32 programming in Delphi 7, using TmySQLQuery from DAC for MySQL as my TDataSet descendant.

推荐答案

如果您只想在自己的线程中使用数据集,您可以使用 synchronize 与主线程通信以进行任何 VCL/UI 更新,例如任何其他组件.或者,更好的是,您可以使用自己的消息系统实现主线程和工作线程之间的通信.

Provided you only want to use the dataset in its own thread, you can just use synchronize to communicate with the main thread for any VCL/UI update, like with any other component. Or, better, you can implement communication between the mainthread and worker threads with your own messaging system.

在此处查看 Hallvard 的线程解决方案:hallvards.blogspot/2008/03/tdm6-knitting-your-own-threads.html

check Hallvard's solution for threading here: hallvards.blogspot/2008/03/tdm6-knitting-your-own-threads.html

或另一个:dn.codegear/article/22411

关于同步及其低效率的一些解释:www.eonclash/Tutorials/Multithreading/MartinHarvey1.1/Ch3.html

for some explanation on synchronize and its inefficiencies: www.eonclash/Tutorials/Multithreading/MartinHarvey1.1/Ch3.html

更多推荐

在 Delphi 中,TDataSet 线程安全吗?

本文发布于:2023-11-25 18:54:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630930.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   Delphi   TDataSet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!