Please help to implement this code whenever my application loads while database operations
I've code like this
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
Please help me how to call this method to multiple forms whenever needed