Multithreading in visual basic 6.0

前端 未结 5 1111
小蘑菇
小蘑菇 2021-02-19 06:19

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

相关标签:
5条回答
  • 2021-02-19 06:26

    Create "Active X" controls to manage your code. Each control has its own thread. You can stack multiple controls doing the same thing, or have individual controls doing unique things.

    EG, You make one to download a file from the net. Add ten controls and you have ten individual threaded downloads running, independent of the thread which the actual program is running. Essentially, they are all just interactive, windows, controlled by an instanced mini-dll program.

    Can't get any easier than that. You can throttle them, turn them on and off, as well as create more, or remove them, as needed. (Indexing just like any other of the "Objects", on a form. Which are all just active-x controls, which are simply managed by the vb-runtime dlls.)

    0 讨论(0)
  • 2021-02-19 06:29

    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:

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

    0 讨论(0)
  • 2021-02-19 06:35

    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.

    0 讨论(0)
  • 2021-02-19 06:41

    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.

    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.

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

    0 讨论(0)
  • 2021-02-19 06:42

    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.

    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.

    0 讨论(0)
提交回复
热议问题