Threading a Process - VB 4.0 From: Steve Thomas
Email: steve.thomas@odyssey.on.ca
Essentially what you need to do is know what processes are still pending. Then you need to allocate some time to each process in turn until all the processes stop. Each process which wants to do something should add itself to a list and needs to keep some state information about itself. When you wish to do some processing you call the process which is next in the list. It starts up and using its own state information (this can be as simple as some static variables) does some more work. Then after a period of time or amount of processing it stops, stores its state information and stops. The process handler then detects that the process it has launched has stopped (I would probably use a label and run this off its change event, or have it check a variable value on a timer event) and goes to the next one on the list. The next process on the list does the same thing.
When a process has decided that it is finished it merely stops as normal and then removes itself from the process list. That way, when the process handler comes around again it doesn't try to launch a completed task. When the process list is empty the process handler shuts down and periodically (using that same timer again) checks the process list to see if a new item has been added.
The really important thing is to structure your processes right. That can be non-trivial. Many languages do all this sort of stuff for you (Perl, LISP, Java, MSVC++), keeping state information and switching between tasks. But in VB you have to do it all manually.
Don't expect great performance as this is usually system level stuff that you are trying to replicate in VB code (which is hardly low level). Also, keep in mind that I have never done this myself - so there may be gotchas which I just haven't thought of. However, the concept intrigues me so I will see if I can do it myself when I get some time. Anyway, I hope this helps out at least giving the basis of what you need to build to do this. Good Luck (I fear you may need it <g>).