Hi, to prevent freezing GUI it is recomennded to use asynchronous variaiton of download operation.
If you are on .net 4.5, just switch the line:
FTP.Download("path_server", "download", ...)
await FTP.DownloadAsync("path_server", "download", ...)
and make the
Download metod async with
async key word. Also remove the
Application.DoEvents call from the
This will await for asynchronous download.
If you are on .net 4.0, it is not such simple, but achievable.
I suggest you to alter
Download method like this:
Private Sub Download()
If Not Connect() Then
FTP.DownloadAsync("path_server", "download", TraversalMode.Recursive, TransferMethod.Copy, ActionOnExistingFiles.OverwriteDifferentSize).ContinueWith(AddressOf Disconnect)
Catch ex As Exception ''# this exception occurs before the asynchronous operation started.
And add overloaded
Disconnect method with
Task parameter like this:
Private Sub Disconnect(ByVal operation As Task)
If operation.IsFaulted Then
ElseIf operation.IsCanceled Then ''# this is set when the download was aborted by FTP.Abort() call.
MessageBox.Show("Download was canceled.")
And also remove the
If you are on earlier version of .net framework, let us know.