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 908565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:44:13+00:00 2026-05-15T16:44:13+00:00

I went through several examples posted online but I cant answer my question. I

  • 0

I went through several examples posted online but I cant answer my question.

I have my ‘p’ variable that is being increased by 1 in the for loop. I want the UI to display the progress of calculation (to show how ‘p’ is increasing from 0 to 1000000). I do the calculation on the separate thread and the I call dispatcher to update the ResultBox in UI. Example:

 int p=0;

 ...

 private void GO(object sender, System.Windows.RoutedEventArgs e)
 {
        new Thread(delegate()
        {
            DoWork();
        }).Start();

}

    void DoWork()
    {
        for (int i = 0; i < 1000; i++)
        {
            for (int j = 0; j < 10000; j++)
            {
                p++;
                this.Dispatcher.BeginInvoke(delegate { ResultBox.Text = p.ToString(); });
            }
        }

    }

For some reason this doesn’t work. However when I put Thread.Sleep(1) just before this.Dispatcher… it works as intended. Does it mean that the UI update (Dispatcher) is called too frequently therefore it freezes?
Is there any other way to do it?

Thank you

  • 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-15T16:44:14+00:00Added an answer on May 15, 2026 at 4:44 pm

    Yes only doing p++ in your loop will not take much of time and inside silverlight, Dispatcher is nothing but a simple queue with delegates, and before silverlight can even update and process its UI, you are pumping too many values on the queue. Imagin what will happen if you keep on adding queue way to faster then the queue is dequeued, then eventually it will hit max limit as well. And eventually it will just stop. If your p++ is replaced with more time consuming task, then you may get good result.

    You must know that our eye usually can see only updates of 30 fps, more then 30 updates per second will not be of any use at all, I will suggest your view update should be reduced to max 10 updates per second for best performance.

    And for showing progress, I think 1 update per second is also enough. First always display updates very slowly, like

    void DoWork() 
    { 
        for (int i = 0; i < 1000; i++) 
        { 
            for (int j = 0; j < 10000; j++) 
            { 
                p++; 
                if((p % 1000)==0){
                     this.Dispatcher.BeginInvoke(delegate 
                          { ResultBox.Text = p.ToString(); });
                } 
            } 
        } 
    
    } 
    

    Now you can increaes/decrease 1000 to some suitable multipler of 10 to adjust your visual update.

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

Sidebar

Related Questions

Suppose I have several 200mb+ files that I want to grep through. How would
I went through a similar question here . But I am yet not clear
I went through all the examples online and could not figure out how to
I went through a document at Adobe Livedocs that describes working with pdf: http://livedocs.adobe.com/flex/3/html/help.html?content=PDF_1.html
I went through couple of articles that talk about Web Workers in HTML5 and
I went through tons of questions about this subject, but still failed to find
I went through these instructions: http://docs.amazonwebservices.com/AmazonRDS/latest/GettingStartedGuide/ But still can't connect to the database using
I went through all the questions on SOF and did my homework but still
I went through a period of being interested in how quantum computers work and
I went through a java tutorial that allowed me to create a text file

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.