在vb6中的编程中使用线程 [英] To use thread in programming in vb6

查看:97
本文介绍了在vb6中的编程中使用线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编程,以使用不同的随机函数以十六进制生成密钥,并将其写入文本文件中.我只有两个cmd按钮和状态栏,用于显示当前时间和进程状态.现在,单击cmd按钮进行密钥生成时,表单将被锁定,所有其他活动都被挂起,甚至是时间被挂起,直到过程结束.我什至不能中止两者之间的过程.我想在可能的情况下使用线程解决此问题.我该怎么做,请提出建议.否则,如果还有其他方法可以解决此问题,请提出建议.

I am programming to generate keys in hexadecimal using different random function and write it in the text file. I have only two cmd buttons and status bar which displays the current time and the status of the process. Now on clicking the cmd button for keygeneration the form gets locked up and all the other activity is suspended that is even the time is suspended until the process is over. i can even not abort the process in between. I want to solve this problem using the thread if possible. how do i do that please suggest. Else if there is any other method to sort out this issue please suggest.

感谢您的宝贵帮助

推荐答案

在VB6中执行多线程的唯一合法"方法是通过ActiveX EXE,只需在项目属性对话框中使用每个对象的线程"选项即可. Matt Curland有一个很好的示例,说明了如何将标准EXE转换为多线程ActiveX EXE.这样做可以使VB6调试器正常运行而不会崩溃,因为在IDE中,所有操作都在单个线程上执行.

The only "legal" way to do multi-threading in VB6 is through ActiveX EXEs -- just use the thread per object option on the project properties dialog. Matt Curland has a good example how to convert your Standard EXE to a multi-threaded ActiveX EXE. Doing it this way allows VB6 debugger to works w/o crashes because in the IDE everything is executed on a single thread.

如果要减少ActiveX EXE多线程的开销,则必须使用不支持但仍可行的进程内多线程.检查紧凑型进程内多线程:具有示例UI的FolderWatcher ,用于安全使用CreateThread并安全地在新线程上初始化VB6运行时(再次由Matt Curland提供).

If you want to cut down the overhead of ActiveX EXE multi-threading then you have to use in-proc multi-threading which is not supported but still doable. Check Compact In-Process Multi-threading: A FolderWatcher with sample UI for a way to safely use CreateThread and to safely initialize VB6 run-time on the new thread (courtesy Matt Curland again).

您可能想查看他的 Advanced Visual Basic 6 书以了解更多详细信息.

You might want to check his Advanced Visual Basic 6 book for more details.

这篇关于在vb6中的编程中使用线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆