我在执行耗时操作(for循环)时使用线程来显示进度窗口。在该操作之后我想停止线程。但是方法“ ShowProgressDialog ”没有被调用。我使用相同的方法其他工作正常的事件。下面是代码。
Private Sub TSBRSToLoc_Click(sender As System.Object, e As System.EventArgs) Handles TSBRSToLoc.Click
Try
If Not BWRRStoLoc.IsBusy Then
Dim backgroundThred As New Thread(AddressOf ShowProgressDialog)
backgroundThred.IsBackground = True
'Dim formProgree As New ProgressForm
backgroundThred.Start()
DisableBtns(sender)
ProgressBarCompare.Value = 0
lblProgStatus.Text = ""
Dim filesSize As Long = 0
For index As Integer = 0 To ObjlsViewCompare.Items.Count - 1
Dim file As File = ObjlsViewCompare.GetModelObject(index)
If Not file.Status = MatchStatus.MisingOnRackSpace Then
filesSize = filesSize + file.SizeOnRackSpace
End If
Next
ProgressBarCompare.Maximum = filesSize
' formProgree.Close()
backgroundThred.Abort()
backgroundThred.Join()
BWRRStoLoc.RunWorkerAsync()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub