I have a backup utility that copies all files and folder into a backup area

This can take some time as the files take up 92Mb over a 1Mbps Data Link


I have added multi-threading to the utility so that the copy can be aborted and so the GUI keeps active.
but i would like to add a progress bar based on the current number of files copied.

The only problem is that the only area that can access the progress bar is the Main Thread which is not the Thread doing the file copies.

Is there any way to put the Progress bar in the copying thread, Access the forms control from another thread or create a new form control that is on the Form but generated by the Copying Thread?

Is there any way to put the Progress bar in the copying thread, Access the forms control from another thread or create a new form control that is on the Form but generated by the Copying Thread?

Yes, there is! :) What you need to do is access the controls through a dummy interface that calls Invoke on the control instead of manipulating it directly if it's not on the main thread.

Delegate Sub SetProgressPropertyCallback( ByVal property As String, ByVal value As Integer )

Private Sub SetProgressProperty( ByVal property As String, ByVal value As integer )
  If ProgressBar1.InvokeRequired Then
    Dim d As New SetProgressPropertyCallback( AddressOf SetProgressProperty )

    Me.Invoke( d, New Object() { property, value } )
  Else
    Select Case property
      Case "Value"
        ProgressBar1.Value = value
      Case "Max"
        ProgressBar1.Maximum = value
      Case "Min"
        ProgressBar1.Minimum = value
    End Select
  End If
End Sub
This question has already been answered. Start a new discussion instead.