Click here to Skip to main content
15,886,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
public void _backgroundWorkerDoWork(object sender, DoWorkEventArgs e)
       {


Some Code ......
_backgroundWorker.ReportProgress(1);

Some Code ......
_backgroundWorker.ReportProgress(10);

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




}



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



on GUI

Please help..
.
Posted
Updated 15-Jan-13 0:27am
v2

1 solution

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
C#
new DownloadProgressChangedEventHandler(ProgressChanged)
to
C#
new DownlaodProgressChangedEventHandler(DownloadProgressChanged)

so the method name doesn't interfere with the "other" ProgressChanged method.

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

[/Edit]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900