Threads, progressbar, and webclient

  • Thread starter Thread starter Lisa
  • Start date Start date
L

Lisa

Hi,

I'm trying to show some sign of activity while my app downloads a file from
the internet. My download routine is such:

Private Sub DownloadWebFile()
Dim wdc As New System.Net.WebClient()
Try
wdc.DownloadFile(FTD, "temp.temp") 'FTD is a global string, the
address & filename to download
Catch
MsgBox(Err.Description)
End Try
End Sub

I invoke the DownloadWebFile from the only form in the project in a new
thread, like so:

Me.ProgressBar1.Visible = True
Timer1.Start()
Dim th As New Threading.Thread(AddressOf DownloadWebFile)
th.Start()
While th.ThreadState.Running
End While
Me.ProgressBar1.Visible = False
Timer1.Stop()

The timer event just cycles the progress bar. I don't care about accurately
showing bytes downloaded, I just want some activity

When running the code, I get an exception msg "Could not find file
"temp.temp". Interestingly, if I use the wdc.DownloadFile call in the main
thread, I do not get this exception (course, I don't get a UI update,
either). Any ideas why I get this exception?

Thanks
 
Back
Top