tags:

views:

270

answers:

5

Using VB6

At the time of executing, it showing white blank screen while it was working with database, How to avoid the white blank screen in VB6.

WHITE BLANK SCREEN MEANS HANGING (WHEN IT WAS WORKING WITH DATABASE).

How to avoid that?

+1  A: 

You should work with data base in separate thread, and any time-consuming operation should be run in a separate thread too. In this case your user interface won't be frozen.

Restuta
Not so easy. This is VB6 we are talking about.
AngryHacker
What is no so easy? Threading approaches is the same on almost every platform.
Restuta
No, it's not the same on every platform. VB6 doesn't support multiple threads in the same exe program.
MarkJ
Restuta
The MSJ article is about VB5. If you try that in VB6 you get all sorts of crashes. I haven't seen the PlanetSourceCode stuff before, but my expectation is that it causes crashes too.
MarkJ
Pscode sample is a rip off of M. Curland's multi-threading samples.
wqw
@wqw. You're right, it does seem to be based on Matt Curland's book Advanced Visual Basic. In that case I recommend buying the book instead - and using it with care, it's *very* hardcore stuff.
MarkJ
A: 

Your first instinct should be to put your resource-intensive operations in a separate thread. This is a bit difficult in VB6, although possible (but not recommended) if you invoke the native CreateThread API.

You can also migrate to VB.NET, and use Thread objects natively.

Dmitry Brant
There's many better ways than using CreateThread. Use ADO's native support for asynchronous operations, or delegate to an ActiveX exe as in AngryHacker's answer.
MarkJ
+4  A: 

I assume you mean that the GUI won't redraw itself when executing a long-running operation. (Shouldn't actually be that visible starting with Vista, but I digress).

If your long-running operation is composed of several steps or tight loops, then you can sprinkle a call to DoEvents every once in a while to cause the form to remain somewhat responsive even when doing work.

Another option would be to migrate your long-running work into a separate thread but last I looked this wasn't exactly trivial or easily possible in VB6.

Joey
People always seem to overlook the simple methods when worrying about background processing on a separate thread in VB6. Gopal's talking about database operations - so just use ADO's native support for asynchronous processing. Alternatively, follow AngryHacker's answer and delegate the work to an ActiveX exe so it runs out-of-process in a separate thread. Both solutions get the job done with a minimum of fuss (and it's easier than classic multithreading in .NET IMHO).
MarkJ
+1  A: 

This is actually the same problem as your "How to exit the program immediately" question. In both cases, the problem is that your database operation is blocking the VB6 program from executing.

  • The answer you accepted for the other question - use ADO to carry out the operations asynchronously - will also solve this blank screen problem.
  • Or if you prefer, follow one of my suggestions in my answer to your other question and use a .NET background worker component through Interop like this.
  • Or follow my other suggestion and delegate the database work to an ActiveX exe like this. EDIT AngryHacker's nice answer to this question uses this method.
MarkJ
+1  A: 

I posted this as an answer to another question, but the pattern applies here as well:

VB6, on its own, is single threaded. However, you can make it somewhat multithreaded via the use of ActiveX EXE that run in their own process, yet still are tethered to the original VB6-created EXE.

What I've used in the past is the Timer object in conjunction with an ActiveX EXE. This approach will give you an ability to localize all the downloading logic in one place, control it like you control a regular object and have it run in a separate EXE, thus by default making it multi-threaded.

So the way this works is like so:

You call the LongRunningOperation method on the ActiveX EXE object In the LongRunningOperation method, you instantiate the Timer and have it kick off almost immediately. You get out of the LongRunningOperation method, thus giving control back to the entity that called it. Then you communicate back to the main app via Events (e.g. LongRunningOperationProgress or LongRunningOperationComplete, etc...)

I recommend the Timer object from Karl Petersen.

AngryHacker
+1. I suggested this in my answer to Gopal's other question about background work in VB6. http://stackoverflow.com/questions/1264513/how-to-exit-the-program-immediately/1265586#1265586
MarkJ