Click here to Skip to main content
11,925,851 members (63,900 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WPF
I have a Process running in background worker .
i need to implement another DownloadProgressChangedEventHandler for Downloading Process of the file and need to show Progress in percentage on UI.Complete Code is in Class file

Code sample

public void _backgroundWorkerDoWork(object sender, DoWorkEventArgs e)

Some Code ......

Some Code ......

_wbClient = new WebClient();
             _wbClient.DownloadFile(SeverPath +FileName, DownLoadedFilePath +FileName);


Need to show download Progreess of Webclient using
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
              webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

on GUI

Please help..
Posted 15-Jan-13 1:10am
Edited 15-Jan-13 1:27am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The BackgroundWorker class[^] offers a method ReportProgress[^] that causes the ProgressChanged[^] event to be risen not in the working thread but in the thread that created the BackgroundWorker. Usually that is the GUI thread. You can therefore call the method in the worker thread and handle the event in the GUI thread, which can change a label without hassle.

Now you have to rename
new DownloadProgressChangedEventHandler(ProgressChanged)
new DownlaodProgressChangedEventHandler(DownloadProgressChanged)
so the method name doesn't interfere with the "other" ProgressChanged method.

Then implement
public void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    DownloadProgressBar.Value = e.ProgressPercentage;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100