2 つの BackgroundWorker を作成しましたが、2 番目の BackgroundWorker がまったく機能していないようです。「Private Sub BackgroundWorker2_DoWork」の下にメッセージボックス インジケーターを配置しましたが、トリガーされましたが、その下のコードはそうではありませんでした。これは、問題が発生している私の BackgroundWorker の完全なコードです。これを引き起こしているものはありますか?
アプリケーションがハングアップする大量のファイルを処理しているため、プログラムには2つのBackgroundWorkersが本当に必要です。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
If BackgroundWorker2.IsBusy <> True Then
BackgroundWorker2.RunWorkerAsync()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub BackgroundWorker2_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
Dim worker1 As System.ComponentModel.BackgroundWorker = CType(sender, System.ComponentModel.BackgroundWorker)
Try
MessageBox.Show("the program was able to open me")
'this message box above was able to display but the codes below were not processed
Dim Stream As System.IO.FileStream
Dim Index As Integer = 0
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "D:\work\base tremble"
openFileDialog1.Filter = "txt files (*.txt)|*.txt"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
'This line opens the file the user selected and sets the stream object
Stream = openFileDialog1.OpenFile()
If (Stream IsNot Nothing) Then
'create the reader here and use the stream you got from the file open dialog
Dim sReader As New System.IO.StreamReader(Stream)
Do While sReader.Peek >= 0
ReDim Preserve eArray(Index)
eArray(Index) = sReader.ReadLine
RichTextBox3.Text = eArray(Index)
Index += 1
worker1.ReportProgress(Index)
'Delay(2)
Loop
Label1.Text = "0/" & eArray.Length & ""
End If
Catch Ex As Exception
MessageBox.Show(Ex.Message)
Finally
If (Stream IsNot Nothing) Then
Stream.Close()
End If
End Try
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub BackgroundWorker2_ProgressChanged(sender As System.Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker2.ProgressChanged
Try
'Label1.Text = e.ProgressPercentage.ToString()
Me.ProgressBar2.Value = e.ProgressPercentage
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub BackgroundWorker2_Completed(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker2.RunWorkerCompleted
Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub