【发布时间】:2011-08-08 17:54:08
【问题描述】:
我无法更新进度条。只要有一个移动的选框栏,我就可以了。基本上,我正在阅读 SqliteReader.vb 类中的数据库例程。我是 Visual Basic 的新手,我确定我需要使用 worker_DoWork 例程,但我不确定如何将来自 Form1: graphData、graphComputations、m_debug 的变量公开给 worker_DoWork 子程序。这通常是怎么做的?
Public Class SqliteReader
Public Sub ReadDataBase
End Sub
End Class
这是更新主窗体 Form1.vb 上的图形(zedgraph 元素)。我像这样从主窗体调用进度条:
ProgressBar.Initialize(channelArray, computationArray, m_debug)
ProgressBar.vb 下面:
Partial Public Class ProgressBar
Dim DataAcquisition As New SqliteReader
Dim WithEvents worker As New BackgroundWorker
Public Sub Initialize(ByRef graphData As Channels(), ByRef graphComputations As Computations(), ByVal m_debug As Integer)
DataAcquisition = SqliteReader.GetInstance()
Me.Show()
Me.Update()
Dim Update_Thread As Thread(AddressOf Update_ThreadExecute)
Update_Thread.Priority = ThreadPriority.Normal
Update_Thread.Start()
DataAcquisition.ParseEntireDatabase(graphData, graphComputations, m_debug)
Me.Close()
End Sub
Private Sub ProgressBarStart(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataAcquisition = SqliteReader.GetInstance()
progress.Style = ProgressBarStyle.Marquee
worker.WorkerReportsProgress = True
worker.WorkerSupportsCancellation = True
worker.RunWorkerAsync()
End Sub
Private Sub worker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles worker.DoWork
Dim worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
DataAcquisition = SqliteReader.GetInstance()
' I probably need
' DataAcquisition.ParseEntireDatabase(graphData, graphComputations, m_debug)
' here... but how do I expose graphdata, graphcomputations and m_debug to this sub?
End Sub
Private Sub worker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles worker.ProgressChanged
dataProgress = CInt(((DataAcquisition.currentRow + 1) / DataAcquisition.totalRows) * 100)
progress.Value = dataProgress
End Sub
【问题讨论】:
标签: vb.net progress-bar