Multitasking in Visual Basic

For the requirement of one of my projects, I’ve created a basic bare bone working example of multitasking application in Visual Basic 6. I called it a working example because this is the first stable one after several crashes and performing some fine-tunings, at least for now 🙂

Basically this sample consists of just one thread and a button to checks the running status of the thread. Let’s just see how this bare bone in action. When I activates the sample, it will present itself as a form with three buttons :

Let’s see the codes when the “start” button is clicked :

I’ll first commented the first two statement to let it run in a conventional way. You can see that it called the “test_function” that basically do nothing other than sleeping :

The above function will first assign some global string variable with “Phase 1” and sleeps for 5 seconds to simulate very long process, and goes to “Phase 2” again perform some “processing” for five more seconds.

When I clicked the “start” button, the form will freezing for 10 seconds (i.e. I can’t click any button or performing any other operations) before it shows the “finished” message.

In this case, there is no way to inquiry the status of the routine within the span of the execution. Now let’s uncomment the “CreateThread” call and performing necessary routine to handle the set and reset event object and codes the “check” button for status checking by accessing the global variable :

Now when “start” button is clicked, I can still perform another task such as checking the process status :

You can download the sample code here :


You have to rename it to .zip extension before performing extraction process.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: