Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3234956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:27:05+00:00 2026-05-17T17:27:05+00:00

I am refactoring my program to use Parallel.ForEach. Before, when I was using a

  • 0

I am refactoring my program to use Parallel.ForEach. Before, when I was using a regular for loop, I was updating a WPF progress bar using Dispatcher, displaying the % completed by dividing the current array index by the array size. With a parallel foreach loop this does not display properly i.e. % jumps eratically, which is expected.

How can I update a WPF progress bar from a parallel for each loop so I can track the number of completed iterations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:27:05+00:00Added an answer on May 17, 2026 at 5:27 pm

    As SLaks suggests, you should just increment the progress bar value instead of setting it to the current index that you got from the Parallel.For method.

    However, I would seriously consider using some less expensive way than sending a message to the UI thread with every iteration. If you have a large number of iterations, then sending a message with every iteration could be quite demanding. You could declare a local variable count and use Interlocked.Increment to increment the variable safely in the body of the parallelized loop.

    • Then you could use something like if (count % 10 == 0) // ... to update the GUI only after 10 iterations. (This is not fully correct, as other threads may update the count before you check, but if it is just for the purpose of GUI notificiation, then it shouldn’t matter – you definitely don’t want to use lock in the loop body).

    • Alternatively, you could create a Timer that would repeatedly check the value of count from the GUI thread and update the progress bar. This is perhaps even easier and you can guarantee that the progress bar will be updated enough often, but not more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am refactoring a (rather long) C program using Visual Studio Professional 2008 (9.0.30729.4462
I am working on a learning program and using the Code Rush refactoring tool
I'm refactoring a program that has a lot of nested calls such as ServiceManagement.getGlobalizationService()
I wrote a small program using a custom indexOf function but wanted to dismiss
I am writing refactoring a Silverlight program to consumes a portion of its existing
I know that refactoring is changing the structure of a program so that the
Hey, I am in the process of refactoring a program that requires some amount
Scenario: I am in the process of refactoring one of our applications to use
What does the term 'poorly factored' and 'refactoring' a program mean? Can you give
I'm refactoring a C# program that calls a stored procedure that ends with: SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.