我想创建自动进度条,当我运行程序时会弹出...
我的程序有6个函数/ sub运行查询需要很长时间才能完成,关于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
我不知道每个函数的经过时间,所以我在for loop
中使用随机整数
答案 0 :(得分:0)
首先,您应该在致电Visible
之前设置ProgressBar
的{{1}}属性。
其次,您应该将RunWorkerAsync
与某些内容进行比较。
第三,如果i Mod 10000000
达到10000000,则i
将超过100。