We help IT Professionals succeed at work.

Multitasking and multithreading inVB

ngomte asked
Hi Friends
I want to perform multitasking in my apllication.my requirement is like this.
 i have to load image from database server and also perform validations.since loading image take too much time that I have to wait for it.i want to load Image in the backgroud processing so that Image gets loaded while validations  complted.
 can anyone help me.
i am using Vb6.0,oracle database server 8.1.7
Thanks and regards
Watch Question


Since unlike VC++ it is not possible to create thread in VB, you could tackle the scenario by creating an outproc server component( ActiveX exe) in VB which would be responsible for loading the image. Your loading component will be executing in different process space, so your application could run simultaneously.
there are many solutions to do threading in vb (http://www.google.com/search?q=vb+multithreading)

Create another project make it an axtiveX exe that runs the process you want to multitask. Put a timer on the form and set the interval to 1 in the timer event put set the timer to disabled that way your code will only execute once, then run the code you want closeing the form when it has finished. You can event put an event in that it calls when it has finished.
Create a public Procedure that loads the form and stores the variable you need then (hidden). modeless

In your original program add a reference to the 2nd (compiled) program and declare it with events then you call call the process and contine executing the code in you first project. when the secound projects timer event runs you multi-task process will begin. You should then be able to create as many references to the 2nd program and run multi tasks.

hope this helps

In VB 5 it was possible to call the CreateThread API and do a multi-threaded VB application, but Microsoft removed support for that in VB 6 (they changed the threading model I think).

I've heard that there are techniques for multi-threading in VB 6 but I haven't seen any examples that work.

You can put a timer on your form, and put the load picture code inside of the timer.  This will allow the picture loading code to execute in the background, however, if you have a tight loop, it will steal all of the CPU from the rest of your app, so, your app will just freeze.

Depending on your code for reading the image from the database, you might be able to get around this.  If your code is using the GetChunk method, then this method is being called in a loop.  Inside of that loop, if you do a DoEvents then that should cut a little CPU to the rest of your User Interface.

However, I should point out that Microsoft never recommends doing a DoEvents inside of a timer, I think they suggest that if other processes have loaded up the event queue, then you might not ever make it back inside of the timer event.  That has never happened to me, but it's a small possibility.


Thanks mdougan

Explore More ContentExplore courses, solutions, and other research materials related to this topic.