Thread - Two Proesses


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Thread - Two Proesses

  1. #1
    Join Date
    Dec 2004
    Posts
    717

    Thread - Two Proesses

    I have some problems in Thread [.Net].

    There are two forms in my project such as frmMain and frmProgressBar.
    I write some codes to load many data from Database in frmMain_Load() Event.
    I want to display progressbar while the data are loading from the database.

    How should I do?

    I have tried with these codes

    In frmMain_Load() Event
    Code:
    Dim dataloader As New System.Threading.ThreadStart(AddressOf LoadData)
    Dim newThread As New System.Threading.Thread(dataloader)
    newThread.Start()
    
    ds = ObjMailCenter.GetMails
    tdbMailsList.DataSource = ds.Tables(0)
    tdbMailsList.Refresh()
    Code:
        Private Sub LoadData()
            Dim ObjProgressBar As New frmProgressBar
            ObjProgressBar.Show()
            System.Threading.Thread.Sleep(1000)
        End Sub

    In frmProgressbar, there is one timer to change the value of progressbar.

    Any help would be appreciated. :-)
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    A progress bar works well with a task like copying files, because you know the total amount of work to do (e.g., the total number of files) and how much of the work you've completed so far (e.g., how many files you've finished copying). It's also easy to break up the task into units; you can, for example, update the progress bar after each file is finished copying.

    With a database transaction, however, your code has no way of knowing how long it's going to take or how much of the task has completed, so a progress bar doesn't make much sense. Instead, you might try using a technique like the one described in this article: http://msdn.microsoft.com/msdnmag/is...dvancedBasics/
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Dec 2004
    Posts
    717
    Thanks.
    That's why, what i was planning to do is
    first, I want to display "main form". [It's first thread.] I don't want to bind data from database at that time.
    And then, I want to show "ProgressBar". [It's second thread.]
    Then, I want to bind the data from "MainForm" while the "ProgressbarForm" will be displaying the progress between min value and max value of the progressbar again and again.
    finally, I want to hide "ProgressBar Form" as soon as Data Binding Complete.

    So, I don't need to know how much time it will take to bind the data from the database.
    If data binding process is completed. you can to close "Progressbar Form".
    That is. :-)
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    With what part of that process do you need help?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Dec 2004
    Posts
    717
    Code:
    Module modGlobal
        Public Splash As New frmSplash 'Your Splash Form 
    
        Dim newThreadProgressBar As New System.Threading.Thread(AddressOf NewThreadProcedureForProgressbar)
        Dim newThreadRoot As New System.Threading.Thread(AddressOf NewThreadProcedure)
    
        Sub NewThreadProcedure()
            Application.Run(New Root(True))
        End Sub
        Sub NewThreadProcedureForProgressbar()
            Application.Run(New frmProgressBar(True))
        End Sub
        Public Sub Main()
            Splash.Show()
            Application.DoEvents()
    
            newThreadRoot.Sleep(1000) 'Allows Extra Display time of Splash Screen 
            newThreadRoot.Priority = Threading.ThreadPriority.Highest
            newThreadRoot.Start()
            Application.DoEvents()
    
            newThreadProgressBar.Sleep(1000) 'Allows Extra Display time of Splash Screen 
            newThreadProgressBar.Priority = Threading.ThreadPriority.BelowNormal
            newThreadProgressBar.Start()
            Application.DoEvents()
        End Sub
    End Module
    I wrote like that.
    the "ProgressbarForm" will be displaying the progress between min value and max value of the progressbar again and again during the data are still binding in "Main Form".
    When data has been binded, I want to close "frmProcessBar" form.
    How can I close this Form??
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You must declare ProgressBarForm so that it is visible to the procedure doing the data binding. Instead of Application.Run(New frmProgressBar(True)), try declaring the ProgressBarForm alongside the Splash form:

    Public Splash As New frmSplash
    Public ProgressBarForm As New frmProgressBar

    NewThreadProcedureForProgressbar then becomes:

    Application.Run(ProgressBarForm)

    Then you may simply close modGlobal.ProgressBarForm when your data binding is complete.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Dec 2004
    Posts
    717
    OK. I got it. Thanks.
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center