0
我想創建,將彈出當我跑我的程序自動進度條..VB網的BackgroundWorker +進度條
我的計劃已經6個功能/分,其運行的查詢花了很長的時間來完成,這是大約就input
約1-2分鐘,我使用backgroundworker
處理線程,並與progressbar
這裏將結合這是我的代碼
的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 progress bar
沒有完成
對於第二個問題之前彈出
for loop
在Do_work
事件 我不知道ow每個函數的流逝時間,所以我使用隨機整數for loop
你能幫我糾正我的程序嗎?非常感謝你.. :)
上'formLoad',我已經設置了'progressBar'屬性爲TRUE; ..然後設置成'錯誤'backgroundworker'事件'progressChanged' ..但它仍然沒有出現..你可以告訴我如何比較..我沒有得到的邏輯,如何設置我的程序在'doWork'事件的持續時間因爲我不知道如何獲得我的功能的總運行時間 –