用vb6实现多线程

发布于 2024-10-21 05:57:02 字数 87 浏览 1 评论 0原文

我的任务是通过连接到电脑的多个串行端口实现自动化过程。 我如何使用 vb6 实现多线程,以通过附加的串行端口独立执行一些自动化任务?

提前致谢。

I Have this task of implementing automation process through multiple serial ports attached to the pc.
How can i implement multi threading with vb6 to independently do some automation tasks through the attached serial ports?

Thanks in advance.

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

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

发布评论

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

评论(3

话少心凉 2024-10-28 05:57:03

不,vb6 不支持多线程。它通过破解 winapi 在 vb5 中工作,但在 vb6 中完全被破坏。错误处理被破坏,一个线程中出现错误会使所有线程崩溃。移至 vb.net 将其恢复。

No, vb6 doesn't support multi-threading. It sorta worked in vb5 by hacking the winapi but got completely broken in vb6. The error handling is busted, getting an error in one thread crashes all of them. Move up to vb.net to get it back.

满身野味 2024-10-28 05:57:03

Desaware 的 SpyWorks 产品(现在作为 UniversalCOM 出售)有一个用于创建VB6 中的线程。

另外,请查看“低开销的更好的多线程”(第 1 部分第2部分),ThreadRunner (4 部分,请参阅作者其他帖子)和 MThreadVB 免费开源解决方案。我没有亲自尝试过这些,但总体上都受到社区的好评。

VB6 显然不是为传统意义上的线程设计的,但使用第 3 方组件或一些创造性的编码,它可以实现。

Desaware's SpyWorks product (now sold as UniversalCOM) has a component (dwBackThread) for creating threads in VB6.

Also, check out 'Even Better Multithreading with Low Overhead' (part1 and part2), ThreadRunner (4 parts, see authors other posts) and MThreadVB for free open source solutions. I have not personally tried these but all were generally well received by the community.

VB6 obviously wasn't designed for threads in the traditional sense, but using either 3rd party components or some creative coding, it can be achieved.

著墨染雨君画夕 2024-10-28 05:57:03

如果您避免像在 MS-DOS 下使用 QBasic 一样编写程序的常见错误,那么这通常不是问题。

MSComm 控件可以异步使用,在输入或错误时引发 OnComm 事件。这样做而不是编写嗡嗡声循环轮询状态(更糟糕的是调用 DoEvents() 来尝试保持响应)可以消除对显式工作线程的需要。

人们通过这种方式编写 TCP 服务器,可以管理数百甚至数千个同时连接,从而取得良好的效果。您可以轻松地对串行端口通信执行相同的操作,因为以低得多的数据速率处理的“连接”要少得多。

您不需要为每个命令按钮分配一个单独的线程,同样,您也不需要为每个 MSComm 控件分配一个线程。

If you avoid the common mistake of writing your program as if you were using QBasic under MS-DOS this usually isn't a problem.

The MSComm control can be used asynchronously, raising OnComm events on input or errors. Doing this instead of writing buzz-loops polling state (and worse yet calling DoEvents() to try to remain responsive) can eliminate the need for explicit worker threads.

People write TCP servers to good effect this way, managing hundreds or even thousands of simultaneous connections. You can do the same thing for serial port communication easily, since there are far fewer "connections" to handle at much lower data rates.

You don't need a separate thread for every command button, and in the same way you don't need a thread for each MSComm control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文