473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Threads, progressbar, and webclient

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
Nov 20 '05 #1
1 2060
Hi,

Watch these 2 msdn tv episodes they show you how to what you want.

http://msdn.microsoft.com/msdntv/epi...B/manifest.xml

http://msdn.microsoft.com/msdntv/epi...B/manifest.xml

Ken
----------------------
"Lisa" <sp*********@herplace.com> wrote in message
news:TL********************@eatel.net...
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

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bartlomiej Rymarski | last post by:
Hello, I'm writing this little program, and I've came across a function that I need to call. Since the execution of the function takes a real long time I want to put a timer, or an animated...
12
by: Grant | last post by:
I am having great difficulty understanding this and any code samples I find online are kilometres long and complicated to understand...Please could someone give me a simple exampe of how to get a...
1
by: andreas.baus | last post by:
Hi. I'm trying to figure out how to properly start and stop threads from a windows form. One thing I still have a problem with is how to make sure the spawned thread(s) are shut down when the...
8
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied....
1
by: nobody | last post by:
Hi I'm currently developing a Windows application. At the start of the application I load several tables into datatables in a dataset. I also use a progressbar to show the user how much percent...
3
by: Ritesh Raj Sarraf | last post by:
Hi, I have a small application, written in Python, that uses threads. The application uses function foo() to download files from the web. As it reads data from the web server, it runs a progress...
2
by: Ezequiel | last post by:
Hi, I´m coding an application that is able to download various mp3 files at the same time. For each mp3 download i´m using a thread. Each thread uses System.net.WebClient. If i try to download 3...
6
by: DaTurk | last post by:
Here's a quick question, say I have a class with a main routine, we'll just call it main. Main is on the "main" thread. Now lets have main creat an instance of another class, which creates a...
4
by: Falcon | last post by:
Hi all, I want to fill a TreeView with some heave data. this action may take several minutes and I'd like to show to the user a model dialog with a simple ProgressBar ('Marquee' style). I managed...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.