Some help with threading needed.

Solarion

Honorary Master
Joined
Nov 14, 2012
Messages
21,886
I have this sort of structure

SUB MAIN ()

Sub PullData1()
Sub PullData2()
Sub PullData3()

END SUB()

Each Sub pulls from the DB and dumps it into a new section of a spreadsheet worksheet. The problem is the program is hanging as the overall process takes about 30 seconds (lots of data).

What I want to achieve is in between each sub, or inside each sub, I want to update a progress bar.

There are so many different types of threading and background worker examples on the net that I've become bogged down and confused with what I actually need.

Any advice would be greatly appreciated.
 

biometrics

Honorary Master
Joined
Aug 7, 2003
Messages
71,858
VBScript? I see there is no DoEvents in VBS. How about a timer to fire off the next sub? Does VBS have timers?
 

Solarion

Honorary Master
Joined
Nov 14, 2012
Messages
21,886
Found something that might help. Using 2 or more background workers


Code:
Option Strict On
Option Infer Off

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        ' start Process 1
        BackgroundWorker1.RunWorkerAsync()
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        ' Process 1 code
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        ' start Process 2 (at Process 1 completed)
        BackgroundWorker2.RunWorkerAsync()
    End Sub

    Private Sub BackgroundWorker2_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
        ' Process 2 code
    End Sub

    Private Sub BackgroundWorker2_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker2.RunWorkerCompleted
        ' both Processes completed
    End Sub

End Class
 

tRoN

Executive Member
Joined
Mar 13, 2007
Messages
6,739
I was going to mention laser hair removal is more effective....then I read some posts.
 

Solarion

Honorary Master
Joined
Nov 14, 2012
Messages
21,886
In fact, if you are in a hurry, the example should suffice as a framework around which you can implement your own, but of course the studying will get you further in the long run.

After pulling a late night I managed to come right. That article you linked was a massive help thanks!! :)
 
Top