我使用 Visual Studio 2013 for Visual Basic,我正在努力调试我的多线程程序。
我正在使用 BackgroundWorker,它的工作方式似乎与我认为的不同。
我不明白为什么我的程序在只处理了 ArrayList 中名为arFileName
.
BackgroundWorker1.DoWork 过程中的For Each
语句无法遍历arFileName
以下代码中的整个内容:
Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnSelectCsv.Click
'arFileName is ArrayList and it has enormous counts
ProgressBar1.Maximum = arFileName.Count
Me.Cursor = Cursors.WaitCursor
'Do background
BackgroundWorker1.RunWorkerAsync()
Me.Cursor = Cursors.Arrow
MessageBox.Show("Finished!", "info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork
Dim arNotFoundFile As New ArrayList
'Confirm file exists
For Each filename As String In arFileName ' Here!
If Not IO.File.Exists(filename) Then
arNotFoundFile.Add(filename)
ProgressBar1.Value = ProgressBar1.Value + 1
End If
Next
End Sub