提问人:Nikunj Chovatiya 提问时间:9/22/2022 更新时间:10/28/2022 访问量:42
如何在应用程序加载或从数据库获取大型数据时显示加载表单
How Show Loading form whenever Application Loads or Fetch Large Data from Database
问:
每当我的应用程序在数据库操作时加载时,请帮助实现此代码
我有这样的代码
Private bgw As New BackgroundWorker
Public Sub showLoading()
bgw.WorkerSupportsCancellation = True
AddHandler bgw.DoWork, AddressOf bgw_doWork
AddHandler bgw.RunWorkerCompleted, AddressOf bgw_Complete
If Not bgw.IsBusy = True Then
bgw.RunWorkerAsync()
End If
End Sub
Public Sub closeLoading()
If bgw.WorkerSupportsCancellation = True Then
bgw.CancelAsync()
End If
End Sub
Private Sub bgw_doWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
Dim loadingScreen As New frmLoading
loadingScreen.Show()
While True
If Not bgw.CancellationPending Then
Threading.Thread.Sleep(50)
Else
e.Cancel = True
Exit While
End If
End While
End Sub
Private Sub bgw_Complete(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
Dim lstFrm As New List(Of frmLoading)
lstFrm = Application.OpenForms.OfType(Of frmLoading)()
If lstFrm.Count > 0 Then
For Each frm As frmLoading In lstFrm
frm.Close()
Next
End If
End Sub
请帮助我如何在需要时将此方法调用到多个表单
答:
-1赞
Hao Yu-MSFT
10/28/2022
#1
您的问题似乎是 loadingScreen.ShowDialog()。
使用 loadingScreen.Show() 作为 .只要 Dialog 保持打开状态,ShowDialog() 就会阻止执行。
评论
ProgressBar
PictureBox