Doing Multi Threaded Gui In Visual Basic

Perhaps I've missed the point but its not that hard.

There are two approaches

Use a timer tick and DoEvents.

 Sub Form_Load() 
   'Disable controls that have to wait for your long process.
   cmdThatUsesData.enabled = false 
   'Set timer interval to something low and enable it
   DBLoadingTimer.interval = 1
   DBLoadingTimer.enabled = true 
   DoEvents
   ' do the rest of your form loading
 End Sub 

Sub DBLoadingTimer_Timer() 'Disable the timer DBLoadingTimer.enabled = false

'Do the long process but put doevents every so often

'Enable the controls cmdThatUsesData.enabled = true

End Sub

Use a timer tick and Do heavy stuff in separate activeX exe component

The timer set up if the same but the time calls a method on an object in a separate activeX exe component

You use an Event to signal completion of the task

 Sub DBLoadingTimer_Timer()
   'Disable the timer
   DBLoadingTimer.enabled = false

DBLoader.Loadstuff

End Sub

Sub DBLoader_StuffDone() 'Enable the controls cmdThatUsesData.enabled = true

End Sub

This code is off the top of my head, so probably not exactly right.

The first approach can lead to a jerky GUI if the steps between DoEvents are not small, if they are small the DoEvents introduce a fair bit of overhead.


EditText of this page (last edited March 1, 2002) or FindPage with title or text search