I am attempting to have a progress bar\'s progress change as the WebClient
download progress changes. This code still downloads the file yet when I call s
You should call startDownload()
from the UI thread. The whole idea of WebClient.DownloadFileAsync()
is that it will spawn a worker thread for you automatically without blocking the calling thread. In startDownload()
, you specified callbacks that modify controls which I assume were created by the UI thread. Thus if you call startDownload()
from a background thread it will cause problems, because a thread can only modify UI elements it created.
The way it is supposed to work is you call startDownload()
from the UI thread, startDownload()
as you defined it sets up event call backs that are handled by the UI thread. It then starts the download asynchronously and returns immediately. The UI thread will be notified when the progress changes and the code responsible for updating the progress bar control will execute on the UI thread, and there shouldn't be any problems.