Click here to Skip to main content
Rate this: bad
good
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 ......
_backgroundWorker.ReportProgress(1);
 
Some Code ......
_backgroundWorker.ReportProgress(10);
 
_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
kedar0012.9K
Edited 15-Jan-13 1:27am
v2

1 solution

Rate this: bad
good
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.
 
[Edit]
Now you have to rename
new DownloadProgressChangedEventHandler(ProgressChanged)
to
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;
}
[/Edit]
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
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