Have some code which uploads files to FTP and it takes some time before it ends and reaches next line of code. In the meantime I would like to show a progress bar and freeze window form until it's done. How to achieve that?
WinScp.PutFile(File, destFP, True) '<---this line taking some time
'Progress bar here till it reach next line...
If Not lsbxPicPaths.Items.Contains(destFP) Then
lsbxPicPaths.Items.Add(destFP)
Else
...
For further discussion
Before open.Session i added:
AddHandler session.FileTransferProgress, AddressOf SessionFileTransferProgress
and below staff was created:
Function GetFile(source As String, destination As String, Optional removeSource As Boolean = False)
Dim result As Boolean = True
Try
session.GetFiles(source, destination, removeSource).Check()
Catch ex As Exception
result = False
'Logger.LogIt(Alert.Write(MsgType.ERROR), Eng.Write(EngType.COLLEC), Datasource.ToString & " | " & Me.reportName & " | " & ex.ToString, LogPath, isDebug)
End Try
Return result
End Function
Private Shared Sub SessionFileTransferProgress(sender As Object, e As FileTransferProgressEventArgs)
'Print transfer progress
_lastProgress = e.FileProgress
End Sub
Public Shared _lastProgress As Integer
then calling like this:
Me.Cursor = Cursors.WaitCursor
WinScp.GetFile(myremotePicturePath, ladujZdjeciaPath, True)
form.ProgressBar1.Value = 0
ProgressBar1.Show()
Do
ProgressBar1.Value = WinScpOperation._lastProgress
ProgressBar1.Refresh()
Loop Until ProgressBar1.Value = 1
Me.Cursor = Cursors.Default
but then besides i want to show custom form when progress bar on it and which will show during getting file and show progress then dissaper and unlock parent form. I don;t know how to pass value to my dynamic form's progress bar. I tried to start like this to change my current code:
Me.Cursor = Cursors.WaitCursor
WinScp.GetFile(myremotePicturePath, ladujZdjeciaPath, True)
Dim form As New Form
Dim pb As New ProgressBar
pb.Minimum = 0
pb.Maximum = 1
form.ShowDialog()
'pass value to progress bar
form.ProgressBar1.Value = 0
' ProgressBar1.Hide()
'ProgressBar1.Value = 0
form.Close()
Me.Cursor = Cursors.Default
for further discussion nr.2
New form:
Public Class FrmProgressBarWinscp
Property value As Integer
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
value = 0
ProgressBar1.Value = 0
ProgressBar1.Show()
End Sub
Sub Run()
Do
ProgressBar1.Value = value
ProgressBar1.Refresh()
Loop Until value = 1
MsgBox("Done")
'ProgressBar1.Hide()
'ProgressBar1.Value = 0
End Sub
End Class
and on oryginal form:
WinScp.GetFile(myremotePicturePath, ladujZdjeciaPath, True)
Dim pro As New FrmProgressBarWinscp()
pro.ShowDialog()
Do
pro.value = WinScpOperation._lastProgress
pro.Run()
Loop Until WinScpOperation._lastProgress
Me.Cursor = Cursors.Default