Click here to Skip to main content
12,622,913 members (30,724 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

11.3K views
584 downloads
7 bookmarked
Posted

WPF Progress Bar Update Class

, 3 Feb 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Simple way to update WPF progress bar

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)

Share

About the Author

RFMeyer
Engineer
United States United States
Software Engineer since 1975

You may also be interested in...

Comments and Discussions

 
QuestionHow about databinding? Pin
CzimerA3-Feb-14 22:08
memberCzimerA3-Feb-14 22:08 
AnswerRe: How about databinding? Pin
RFMeyer4-Feb-14 2:36
memberRFMeyer4-Feb-14 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 3 Feb 2014
Article Copyright 2014 by RFMeyer
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid