[2005] Threading/BackgroundWorker and dataset
Dear Folks,
i have seen almost all posts and links on this forum about the above topic
but i cant get to do what i want. And everything has made me confused thats why i need your help.
Scenario:
From a menu button on the mainform, I load a form(childform) that has a datagridview and a good number of controls. The form waits to show up untill the dataset that feeds that datagridview is filled with data. And the number of controls on this form also makes it longer for the form to show up.
So, to avoid puzzling up the user, i would like to show a progress form while the dataset is loading.After the dataset has loaded, the progessform should be disposed off and then the form showsup with the datagridview having all the data. This implies that i need to use a maquee kind of progess since i dont know how long it would take for my dataset to fill.This is not a problem.
How can i do this?
Should i use threading or a background worker and how?
Re: [2005] Threading/BackgroundWorker and dataset
This is what i have, i dont know whether i am on the right track. I dont get good results though.
Fill Dataset in public Module
VB Code:
Public dsOrgs As DataSet
Public Sub FillDataset()
Dim strSQL As String = "SELECT * FROM QryIncidents"
dsOrgs = New DataSet
dsOrgs = connMger.ReturnOleDbData(strAccessConn, strSQL, "QryIncidents")
End Sub
in my Porogress Bar:
VB Code:
'Close progress bar
Public Sub CloseMe(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
On the menu button that calls the child form
VB Code:
Private Sub smnuIncidents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smnuIncidents.Click
Me.smnuIncidents.Visible = False
Me.Refresh()
Me.smnuIncidents.Visible = True
Dim shwPrThread As Thread = New Thread(AddressOf showProgressBar)
shwPrThread.Start()
'Fill dataset from public sub
FillDataset()
shwPrThread.Abort()
Dim closePrThread As Thread = New Thread(AddressOf closeProgressBar)
closePrThread.Start()
'Open Child form
OpenIncidentsForm()
End Sub
Sub that calls the child form
VB Code:
Private Sub OpenIncidentsForm()
If Me.childForm Is Nothing OrElse Me.childForm.IsDisposed Then
Me.childForm = New frmIncidents
Me.AddOwnedForm(Me.childForm)
Me.childForm.MdiParent = Me
Me.childForm.Show()
flagFrmLoaded = True
Else
' If User Tries To Load This form when its still open
' Then just focus on the exitsing form
Me.childForm.Activate()
End If
End Sub
Subs called by threads (located in main form)
VB Code:
Private _progressBar As frmProgressBar
Private Sub showProgressBar()
_progressBar = New frmProgressBar
Application.Run(_progressBar)
End Sub
Private Sub closeProgressBar()
If Not _progressBar Is Nothing Then
Return
End If
_progressBar.Invoke(New EventHandler(AddressOf _progressBar.CloseMe))
_progressBar.Dispose()
_progressBar = Nothing
End Sub
Any Help!!
Re: [2005] Threading/BackgroundWorker and dataset
* bump *
seeking to resolve this!