ProgressBar -- MultiThreading

I have an app that allows the user to click a button which starts a data migration process.  The migration process takes a really long time.  While it runs I need to show the user the status - progressbar, recs processed.  What is the best way to do this? The only way I know to run this process without the form hanging (not responding) is to run it in a seperate thread.  But then I have to talk back to the form to update the progress bar or lablels.  should i start the process with thread.start(proc) and then raiseevents from the process that are handled in the form for updating the controls?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
You have to use a Delegate and the Invoke method to marshal the call onto the controls thread if necessary.

Here is a simple example...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim t As New System.Threading.Thread(AddressOf Me.NewThread)
    End Sub

    Private Delegate Sub UpdateLabelDelegate(ByVal value As String)

    Private Sub NewThread()
        Dim i As Integer
        For i = 1 to 5
            UpdateLabel("Test" & i)
        Next i
    End Sub

    Private Sub UpdateLabel(ByVal value As String)
        If Label1.InvokeRequired Then
            Dim uld As New UpdateLableDelegate(AddressOf UpdateLabel)
            Label1.Invoke(uld, New Object() {value})
            Label1.Text = value
        End If
    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.