vb.net:后台工作者导致UI延迟

时间:2013-12-18 16:56:41

标签: vb.net multithreading

在向用户显示登录屏幕之前,我正在运行后台工作程序来收集一些信息。我在workerCompleted子区域内调用了登录页面,但是在登录页面显示的前几秒内,鼠标移动非常生涩,你无法点击任何按钮,几秒后一切正常。看起来背景工作者并没有真正完成,但无论如何它向我展示了登录页面。有没有办法确定后台工作人员是否真的完成才能继续前进?

感谢。

这是我的代码:

Private check_config_bw As BackgroundWorker = New BackgroundWorker

Public Sub start()

  check_config_bw.WorkerReportsProgress = True
  check_config_bw.WorkerSupportsCancellation = True
  AddHandler check_config_bw.DoWork, AddressOf check_config_bw_DoWork
  AddHandler check_config_bw.ProgressChanged, AddressOf check_config_bw_ProgressChanged
  AddHandler check_config_bw.RunWorkerCompleted, AddressOf check_config_bw_RunWorkerCompleted

  If Not check_config_bw.IsBusy = True Then
     check_config_bw.RunWorkerAsync()
  End If

End Sub

Private Sub check_config_bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
 ' open database connection, check it, move on
End Sub

Private Sub check_config_bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)

        ' dispose of the background worker since it is no longer needed
        ' ------------------------------------------------------------
        check_config_bw.Dispose()

        If check_config_success = True Then

            ' Go on to the next step
            ' ----------------------
            show_login()

        Else
            ' go to configuration page
            ' ------------------------
            configure_application() 

        End If

End Sub

0 个答案:

没有答案