Click here to Skip to main content
Click here to Skip to main content

WPF Progress Bar Update Class

By , 3 Feb 2014
Rate this:
Please Sign up or sign in to vote.

Introduction

The RFM_WPFProgressBarUpdate.cs class allows for easy to implement WPF progress bar updating by three methods:

  1. When the value changes
  2. On demand
  3. When the timer fires, you specify interval in 10ths of a second.

The Visual Studio 2010 solutions for the test application can be downloaded from the links at the top of this tip.

Background

When I want to use a progress bar in WPF, I do a search on the web on how to update the progress bar. I find that one always needs to use the Dispatcher and Invoke or set up a worker thread. In other programming languages, updating the progress bar was a fairly easy task, but not in WPF, relatively speaking. So, I set out to make it as nearly as easy as it is in other languages.

Using the Code

The class "RFM_WPFProgressBarUpdate" has a long name and is located in the RFM namespace. In the code behind where you will use this class, put the following statement in the "using" section of your code:

using pbu = RFM.RFM_WPFProgressBarUpdate; 

At the location you will want to use this update class, you will add your progress bar to the class and receive a handle like so:

var handle = pbu.New(ProgressBar, min, max, value);  OR 
var handle = pbu.New(ProgressBar, min, max, value, 0); 

Then, where you wish to update the progress bar, usually in a loop, do the following:

pbu.CurValue[handle] = value;  OR 
pub.CurValue[handle] += 1;

That is all there is to it. When the statement above is executed, your progress bar will be updated in the background.

When you have finished using the class to update your progress bar, you will want to remove it from the class like so:

pbu.Remove(handle);

The detailed instruction is in the class's source file. There you will learn how to update on demand or use the timer to update your progress bar.

The attached solution contains a test program showing the three methods of updating the WPF progress bar. Here is a screen shot of that test program:

Points of Interest

You may wish to investigate how the pbu.CurValue[handle] is implemented.

History

  • 3rd February, 2014: Initial version

License

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

About the Author

RFMeyer
Engineer
United States United States
Software Engineer since 1975

Comments and Discussions

 
QuestionHow about databinding? PinmemberCzimerA3-Feb-14 21:08 
AnswerRe: How about databinding? PinmemberRFMeyer4-Feb-14 1:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 3 Feb 2014
Article Copyright 2014 by RFMeyer
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid