i want to create automatic progress bar that will popped up when i ran my program..
my program has 6 function/sub which run query that took quite long time to completed, it's approximately around 1-2 minutes regarding input
i'm using backgroundworker
to handle the threads and combine it with progressbar
here's my code
RunWorkerAsync
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.RunWorkerAsync()
End Sub
Do_work
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i As Integer = 0 To 100000000
create_tree()
localtree()
localfrek()
create_combination()
showresult()
If i Mod 10000000 Then
BackgroundWorker1.ReportProgress(i / 100)
End If
Next
End Sub
ProgressChanged
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Visible = True
ProgressBar1.Value = e.ProgressPercentage
End Sub
RunWorkerCompleted
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MessageBox.Show("Task completed!")
End Sub
the problem is
- the
the progress bar
didn't popped up - the function stop before completion
for the second problem i think it because the for loop
that i use in Do_work
event
i don't know the elapsed time of each function that i have, so i use random integer number in for loop
can you please help me to correct my program? thank you very much.. :)