1

i have used progress bar in my application..my application is working fine but the progress bar is blank..it does not show the working progress what is wrong??

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
shruti
  • 51
  • 3
  • 7

3 Answers3

9

Probably you are performing the work in the main GUI thread. This causes all GUI events to be delayed until the task is finished.

Use a BackgroundWorker instead and use its ProgressChanged event to update the progress bar.

Also remember to set WorkerReportsProgress to true on your background worker.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • i have used BackgroundWorker for the progress bar..to show results according to the application running but it is not showing anything its just blank..... – shruti Mar 25 '10 at 07:03
  • @shruti: Can you simplify your code to the simplest possible example that still demonstrates the error you are experiencing and then post your code here so we can see it? – Mark Byers Mar 25 '10 at 07:05
  • @shruti: See my update regarding WorkerReportsProgress. Maybe that solves your problem. – Mark Byers Mar 25 '10 at 07:09
  • yes i did that already..i cant display the code bcoz im doing multiple things and to display all will be very confusing.. im just using the logic that if the work is in progress int percent = (int)((100 * writtenSectors) / burnData.sectorCount); lblStatus.Text = string.Format("Progress: {0}%", percent); statusProgressBar.Value = percent; else { lblStatus.Text = "Progress 0%"; statusProgressBar.Value = 0; } – shruti Mar 25 '10 at 07:26
0

Refer this question of StackOverflow:

Updating DataGrid From a BackGroundWorker

I am assuming you must be accessing UI object using Invoke method.

If not try using following approach (Executes the specified delegate, on the thread that owns the control's underlying window handle, with the specified list of arguments.):


 //In Form.Designer.cs 

ProgressBar progressBar= new ProgressBar ();

//In code behind under Background worker method ProgressVlaueSetter SetProgressValueDel = SetProgressValue;
if (progressBar.InvokeRequired) {
progressBar.Invoke(SetProgressValueDel , 20); }

private delegate void ProgressVlaueSetter (intvalue);

//Set method invoked by background thread private void SetProgressValue(intvalue) { progressBar.Value= value; }

Community
  • 1
  • 1
RockWorld
  • 1,278
  • 2
  • 11
  • 24
0

A compatible operating system and environment are prerequisites for a progress bar to work because the method of drawing the extending bar or blocks on the computer display is not compatible across all platforms. The progress bar type is protected and regulated and may be licensable but would not operate everywhere in a nation, state, province or even a city unless a specific type of progress indication is lawful. Moving code or an application to a different computer type or host system can be plagued with similar issues for other features.

Developer
  • 114
  • 2