How to show percentage of completion on a label ?

  • Thread starter Thread starter Harsha
  • Start date Start date
H

Harsha

Hi,

I am downloading few files from server. I am using Progress Indicator to
show the progress of download. But I also want to show the percentage of
completion and file which is getting download. I tried as given below.
Progress bar is working properly but still label text shows empty.

for (int j = 0; j < keys.Length; j++) {
DownloadFileBinary(htFileNames[keys[j]].ToString(),
"http://xx.xxx.xx.xx/abc.dll);
lblFileName.Text = htFileNames[keys[j]].ToString()
pBar1.Value = pBar1.Value + 1;
}

please tell me how to show the filename on the label filed. Even I tried
using get and set property with out success.

Thanks and Regards,

Harsha.
 
following your lblFileName.Text = statement call
Application.DoEvents( ). This will force the message pump to process any
queued messages and update your label.

Regards,
Rick D.
 
The quick and dirty approach is as Rick said which is to flush the message
pump. But the recomended pattern is to use a worker thread here which notifys
your UI main thread.

For instance in your code example what happens if the user decided he/she
wanted to end the download because it was taking too long?
 
Hi,

Thank you very much for both of you.

I solved this issue. Solution was very simple. I included below line of code
and it worked.

lblFileName.Refresh();

So now the code is

for (int j = 0; j < keys.Length; j++) {
DownloadFileBinary(htFileNames[keys[j]].ToString(),
"http://xx.xxx.xx.xx/abc.dll);
lblFileName.Text = htFileNames[keys[j]].ToString()
lblFileName.Refresh();
pBar1.Value = pBar1.Value + 1;
}


Thanks and Regads,

Harsha.


Simon Hart said:
The quick and dirty approach is as Rick said which is to flush the message
pump. But the recomended pattern is to use a worker thread here which notifys
your UI main thread.

For instance in your code example what happens if the user decided he/she
wanted to end the download because it was taking too long?
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Hi,

I am downloading few files from server. I am using Progress Indicator to
show the progress of download. But I also want to show the percentage of
completion and file which is getting download. I tried as given below.
Progress bar is working properly but still label text shows empty.

for (int j = 0; j < keys.Length; j++) {
DownloadFileBinary(htFileNames[keys[j]].ToString(),
"http://xx.xxx.xx.xx/abc.dll);
lblFileName.Text = htFileNames[keys[j]].ToString()
pBar1.Value = pBar1.Value + 1;
}

please tell me how to show the filename on the label filed. Even I tried
using get and set property with out success.

Thanks and Regards,

Harsha.
 
Back
Top