我正在使用Windows窗体应用程序。点击任何按钮都会变慢。我正在使用2个后台工作者(第一个是做一些排序数据而另一个是不断从服务器通过Web服务获取数据)无法理解发生了什么事情,以前只有一个后台工作者才能正常工作但是在添加第二个工作时应用程序性能变慢,有时会进入“Not Responding State”(双击表单)。 任何人都知道它为什么会这样?如果我停止第二个工人,那么工人又好了。
这是我的第二个BGW的代码
If Not bwProcessData.IsBusy Then
bwProcessData.RunWorkerAsync()
End If
Private Sub bwProcessData_DoWork(sender As Object, e As DoWorkEventArgs) Handles bwProcessData.DoWork
While get_all_server_data
Sync_the_data()
Application.DoEvents()
End While
While IsFutureRecords Or IsPastRecords
If IsFutureRecords Then
While IsFutureRecords
'' API call for all future date records
'' And the update my database
'' if no record found then IsFutureRecords = false
End While
ElseIf IsPastRecords Then
While IsPastRecords
'' API call for all Past date records
'' And the update my database
'' if no record found then IsPastRecords = false
End While
End If
End While
End Sub
Private Sub bwProcessData_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bwProcessData.RunWorkerCompleted
If e.Cancelled Then
Else
Dim run_syn_complete_2 As UpdateUIFrom_Background_2 = New UpdateUIFrom_Background_2(AddressOf run_sync_complete_2)
Dim str_value As String = "Background worker 2"
Me.Invoke(run_syn_complete_2, str_value)
End If
End Sub
Public Sub run_sync_complete_2()
'' Update UI accordingly
End Sub