InertiaM
Well-known member
OK, I admit - I'm confused
I'm trying to write an upload function to copy a database from my desktop to a Pocket PC. I wanted to display a progressbar to show how much it had uploaded, but the progressbar doesnt change at all The method "CopyFileToDevice" doesnt give any events, so I have had to try and calculate the upload time and display the progressbar based on elapsed time.
With the Messagebox, everything works fine - the progressbar displays, moves for 20 seconds and hides just as I would expect. If, however, I replace the messagebox line with the CopyToDevice line, the progressbar doesnt start but does hide at the end of 20 seconds.
Any suggestions please
I'm trying to write an upload function to copy a database from my desktop to a Pocket PC. I wanted to display a progressbar to show how much it had uploaded, but the progressbar doesnt change at all The method "CopyFileToDevice" doesnt give any events, so I have had to try and calculate the upload time and display the progressbar based on elapsed time.
VB.NET:
Imports OpenNETCF.Desktop.Communication
Imports System.ComponentModel
Imports System.Threading
Public Class Form1
Private rPocketPC As RAPI = New RAPI
Private WithEvents TransferWorker As BackgroundWorker = New BackgroundWorker
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
rPocketPC.Connect()
If Not rPocketPC.Connected Then Exit Sub
TransferWorker.WorkerReportsProgress = True
TransferWorker.WorkerSupportsCancellation = True
ProgressBar1.Value = 0
ProgressBar1.Visible = True
'10,625,024 in 45691ms
TransferWorker.RunWorkerAsync(10625024)
Application.DoEvents()
'UPLOAD FUNCTION GOES HERE
MessageBox.Show("UPLOAD")
'rPocketPC.CopyFileToDevice("c:\factory2.sdf", "\Storage Card\factory2.sdf")
rPocketPC.Disconnect()
rPocketPC.Dispose()
'ProgressBar1.Visible = False
End Sub
Private Sub TransferWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles TransferWorker.DoWork
Dim worker As System.ComponentModel.BackgroundWorker = CType(sender, System.ComponentModel.BackgroundWorker)
e.Result = CalculateUploadTime(CType(e.Argument, Long), worker, e)
End Sub
Function CalculateUploadTime(ByVal FileSize As Long, ByVal worker As System.ComponentModel.BackgroundWorker, ByVal e As DoWorkEventArgs) As Long
'TODO: calculate upload time based on file size
Dim iTimer As Integer = 0
While iTimer < 200
iTimer += 1
worker.ReportProgress(Convert.ToInt32((iTimer / 200) * 100))
Threading.Thread.Sleep(100)
End While
worker.CancelAsync()
End Function
Private Sub TransferWorker_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles TransferWorker.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
Application.DoEvents()
End Sub
Private Sub TransferWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles TransferWorker.RunWorkerCompleted
ProgressBar1.Visible = False
End Sub
End Class
With the Messagebox, everything works fine - the progressbar displays, moves for 20 seconds and hides just as I would expect. If, however, I replace the messagebox line with the CopyToDevice line, the progressbar doesnt start but does hide at the end of 20 seconds.
Any suggestions please