Hi Wout
I've run your program and (after a little modification) got an error during transfer. I was quickly able to identify the problem by enabling "Break on exception" within VS.NET. To use this feature, select "Exceptions..." from the "Debug" menu, and then check the checkbox in the "Thrown" column on the "Common Language Runtime Exceptions" row. When you run it now you should see it stopping inside the BytesTransferred event-handler when you try to update the progress bar.
The exception that is thrown is "Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on.". You could also have found this error by looking more closely at the exception that you caught in Start_Transfer(). It is a TargetInvocationException, so you need to look at the InnerException member to see the actual exception that was thrown.
So what's the problem? The problem is that you are trying to update a control on the form from a thread other than the thread that was used to create the control. This is not allowed in Windows Forms, which is quite annoying. Fortunately it's not hard to work around the problem. You need to use the
Control.BeginInvoke(Delegate method, params Object[]) method.
So, instead of your current FtpC_BytesTransferred method, which looks like this:
Public Sub FtpC_BytesTransferred(ByVal sender As Object, ByVal e As EnterpriseDT.Net.Ftp.BytesTransferredEventArgs) Handles FtpC.BytesTransferred
ProgressBar1.Value = e.ByteCount
End Sub
you need to do this:
Delegate Sub UpdateProgressBarDelegate(ByVal byteCount As Long)
Public Sub FtpC_BytesTransferred(ByVal sender As Object, ByVal e As EnterpriseDT.Net.Ftp.BytesTransferredEventArgs) Handles FtpC.BytesTransferred
Dim arguments(0) As Object
arguments(0) = e.ByteCount
ProgressBar1.Invoke(New UpdateProgressBarDelegate(AddressOf UpdateProgressBar), arguments)
End Sub
Private Sub UpdateProgressBar(ByVal ByteCount As Long)
ProgressBar1.Value = ByteCount
End Sub
Please let me know if that solves the problem.
- Hans (EDT)