Results 1 to 3 of 3

Thread: [2005] Threading/BackgroundWorker and dataset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    [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?
    Last edited by maps; Sep 15th, 2006 at 01:19 AM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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:
    1. Public dsOrgs As DataSet
    2.  
    3.  Public Sub FillDataset()
    4.         Dim strSQL As String = "SELECT * FROM QryIncidents"
    5.         dsOrgs = New DataSet
    6.         dsOrgs = connMger.ReturnOleDbData(strAccessConn, strSQL, "QryIncidents")
    7.     End Sub

    in my Porogress Bar:
    VB Code:
    1. 'Close progress bar
    2.     Public Sub CloseMe(ByVal sender As Object, ByVal e As System.EventArgs)
    3.         Me.Close()
    4.     End Sub

    On the menu button that calls the child form
    VB Code:
    1. Private Sub smnuIncidents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smnuIncidents.Click
    2.         Me.smnuIncidents.Visible = False
    3.         Me.Refresh()
    4.         Me.smnuIncidents.Visible = True
    5.  
    6.         Dim shwPrThread As Thread = New Thread(AddressOf showProgressBar)
    7.         shwPrThread.Start()
    8.         'Fill dataset from public sub
    9.         FillDataset()
    10.         shwPrThread.Abort()
    11.  
    12.         Dim closePrThread As Thread = New Thread(AddressOf closeProgressBar)
    13.         closePrThread.Start()
    14.         'Open Child form
    15.         OpenIncidentsForm()
    16.     End Sub

    Sub that calls the child form
    VB Code:
    1. Private Sub OpenIncidentsForm()
    2.         If Me.childForm Is Nothing OrElse Me.childForm.IsDisposed Then
    3.             Me.childForm = New frmIncidents
    4.             Me.AddOwnedForm(Me.childForm)
    5.             Me.childForm.MdiParent = Me
    6.             Me.childForm.Show()
    7.             flagFrmLoaded = True
    8.         Else
    9.             ' If User Tries To Load This form when its still open
    10.             ' Then just focus on the exitsing form
    11.             Me.childForm.Activate()
    12.         End If
    13.     End Sub

    Subs called by threads (located in main form)
    VB Code:
    1. Private _progressBar As frmProgressBar
    2.  
    3. Private Sub showProgressBar()
    4.         _progressBar = New frmProgressBar
    5.         Application.Run(_progressBar)
    6.     End Sub
    7.  
    8.     Private Sub closeProgressBar()
    9.         If Not _progressBar Is Nothing Then
    10.             Return
    11.         End If
    12.         _progressBar.Invoke(New EventHandler(AddressOf _progressBar.CloseMe))
    13.         _progressBar.Dispose()
    14.         _progressBar = Nothing
    15.     End Sub

    Any Help!!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [2005] Threading/BackgroundWorker and dataset

    * bump *
    seeking to resolve this!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width