Results 1 to 2 of 2

Thread: [2005] ProgressBar in new thread on From2

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    38

    [2005] ProgressBar in new thread on From2

    I have a new thread that opens up when I hit a query button. I'm not sure I am opening the "Form2" correctly because I do not see it when running tests however, the debug doesn't pick anything up. Here is the code:

    vb Code:
    1. Public Sub ShowProgBar()
    2.         Dim form2PB As Form = mywindowsapp1.Form2
    3.         form2PB.Show()
    4. End Sub
    5.  
    6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    7.  
    8.         'validate the text fields
    9.         'some code that does some stuff.....
    10.  
    11.         Dim thread1 As System.Threading.Thread
    12.         thread1 = New System.Threading.Thread(AddressOf ShowProgBar)
    13.         thread1.Start()
    14.  
    15.         'more code that does some stuff
    16.         'processes running while progress bar should be displaying
    17.  
    18.         MessageBox.Show("Processes Complete")
    19.  
    20.         Application.Exit()
    21.         'this is also where the progress bar thread should terminate
    22. End Sub

    I am wondering why I am not seeing Form2 (containing my progressbar) during this.

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] ProgressBar in new thread on From2

    You are going about it the wrong way. You should not start the thread and then create the form in that thread because you want all your controls created on the same main thread. What you should be doing is creating the form first, then starting the thread from that form. Now the form and its controls have been created on the same thread as the rest of the UI and you do only the background processing in the background thread.

    I'd also suggest using a BackgroundWorker to make updating the ProgressBar easier.

    http://www.vbforums.com/showthread.php?t=471889
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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