visual basic 6.0中的多线程

时间:2022-02-08 16:32:37

How to implement multi-threading in visual basic 6.0. It would be great if someone can give an example.

如何在visual basic 6.0中实现多线程。如果有人可以举一个例子,那就太棒了。

4 个解决方案

#1


14  

VB6 is not a really good environment for multi-threaded applications. There is no out-of-the-box support, you need to delve into standard WinAPI functions. Take a look at this article, which provides quite a comprehensive sample:

VB6对于多线程应用程序来说不是一个非常好的环境。没有开箱即用的支持,您需要深入研究标准的WinAPI功能。看看这篇文章,它提供了相当全面的示例:

http://www.freevbcode.com/ShowCode.Asp?ID=1287

#2


9  

On several projects I have implemented asynchronous processing in VB6 using multiple processes. Basically having a worker thread within an active exe project that is separate from the main process. The worker exe can then be passed whatever data it needs and started, raising back an event to say it's finished or there is data for the main process.

在几个项目中,我使用多个进程在VB6中实现了异步处理。基本上在活动的exe项目中有一个与主进程分开的工作线程。然后,worker exe可以传递它需要和启动的任何数据,重新启动事件以说明它已完成或主进程有数据。

It's a more resource hungry (an extra process rather than a thread) but VB6 is running in a single threaded apartment and doesn't have any built in support for starting new threads.

这是一个更耗资源(一个额外的进程而不是一个线程),但VB6在一个单线程公寓中运行,并没有任何内置支持来启动新线程。

If you really need to have multiple threads within one process I'd suggest looking at using .net or VC6 rather than VB6.

如果你真的需要在一个进程中有多个线程,我建议使用.net或VC6而不是VB6。

#3


2  

If the problem that you are trying to solve is a long calculation and you want to keep the UI responsive, then one possibility is to frequently call the DoEvents function within your long calculation. This way, your program can process any Windows messages, and thus the UI will respond to user commands. You can also set up a Cancel button to signal your process that it needs to end.

如果您尝试解决的问题是长时间计算并且您希望保持UI响应,那么一种可能性是在长计算中频繁调用DoEvents函数。这样,您的程序可以处理任何Windows消息,因此UI将响应用户命令。您还可以设置“取消”按钮,以指示您需要结束的流程。

If you do this, then you will need to be careful to disable any controls that could cause a problem, such as running the long process a second time after it has started.

如果这样做,那么您需要小心禁用任何可能导致问题的控件,例如在启动后再次运行长进程。

#4


0  

You can use the Interop Forms Toolkit 2.0 for multithreading in VB6. The Toolkit allows you to take advantage of .NET features without being forced onto an upgrade pat. Thus you can also use .NET User Controls as ActiveX controls in VB6.

您可以在VB6中使用Interop Forms Toolkit 2.0进行多线程处理。 Toolkit允许您利用.NET功能而不必强制进行升级。因此,您还可以在VB6中将.NET用户控件用作ActiveX控件。

#1


14  

VB6 is not a really good environment for multi-threaded applications. There is no out-of-the-box support, you need to delve into standard WinAPI functions. Take a look at this article, which provides quite a comprehensive sample:

VB6对于多线程应用程序来说不是一个非常好的环境。没有开箱即用的支持,您需要深入研究标准的WinAPI功能。看看这篇文章,它提供了相当全面的示例:

http://www.freevbcode.com/ShowCode.Asp?ID=1287

#2


9  

On several projects I have implemented asynchronous processing in VB6 using multiple processes. Basically having a worker thread within an active exe project that is separate from the main process. The worker exe can then be passed whatever data it needs and started, raising back an event to say it's finished or there is data for the main process.

在几个项目中,我使用多个进程在VB6中实现了异步处理。基本上在活动的exe项目中有一个与主进程分开的工作线程。然后,worker exe可以传递它需要和启动的任何数据,重新启动事件以说明它已完成或主进程有数据。

It's a more resource hungry (an extra process rather than a thread) but VB6 is running in a single threaded apartment and doesn't have any built in support for starting new threads.

这是一个更耗资源(一个额外的进程而不是一个线程),但VB6在一个单线程公寓中运行,并没有任何内置支持来启动新线程。

If you really need to have multiple threads within one process I'd suggest looking at using .net or VC6 rather than VB6.

如果你真的需要在一个进程中有多个线程,我建议使用.net或VC6而不是VB6。

#3


2  

If the problem that you are trying to solve is a long calculation and you want to keep the UI responsive, then one possibility is to frequently call the DoEvents function within your long calculation. This way, your program can process any Windows messages, and thus the UI will respond to user commands. You can also set up a Cancel button to signal your process that it needs to end.

如果您尝试解决的问题是长时间计算并且您希望保持UI响应,那么一种可能性是在长计算中频繁调用DoEvents函数。这样,您的程序可以处理任何Windows消息,因此UI将响应用户命令。您还可以设置“取消”按钮,以指示您需要结束的流程。

If you do this, then you will need to be careful to disable any controls that could cause a problem, such as running the long process a second time after it has started.

如果这样做,那么您需要小心禁用任何可能导致问题的控件,例如在启动后再次运行长进程。

#4


0  

You can use the Interop Forms Toolkit 2.0 for multithreading in VB6. The Toolkit allows you to take advantage of .NET features without being forced onto an upgrade pat. Thus you can also use .NET User Controls as ActiveX controls in VB6.

您可以在VB6中使用Interop Forms Toolkit 2.0进行多线程处理。 Toolkit允许您利用.NET功能而不必强制进行升级。因此,您还可以在VB6中将.NET用户控件用作ActiveX控件。