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

  • Home
  • SEARCH
  • 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 8988065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:56:16+00:00 2026-06-15T21:56:16+00:00

I tried to update a TextBox.Text to display from 1 to 10 with an

  • 0

I tried to update a TextBox.Text to display from 1 to 10 with an internal of 1 second with the following code. I do not understand why the entire UI sleeps for 10 second before the text is updated to 10, as I though the Thread.Sleep(1000) should belong to a separate background thread created by Dispatcher.BeginInvoke.

What is wrong with my code?

Thread t1 = new Thread(new ThreadStart(
    delegate()
    {
        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
            new Action(delegate()
                {
                    for (int i = 1; i < 11; i++)
                    {
                        mytxt1.Text = "Counter is: " + i.ToString();
                        Thread.Sleep(1000);
                    }
                }));

    }));
t1.Start();
  • 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-06-15T21:56:17+00:00Added an answer on June 15, 2026 at 9:56 pm

    The Action that sets the text is running on the UI thred and that’s why the UI is freezing.

    Due to the limitation that only the Thread that created the instances of UI controls (a.k.a. the UI thread) can modify properties of UI controls, you have to run the code that sets the text on the UI thread. And that’s what you’re doing.

    What you can try, is to have that code run in a Threading.Timer.

    Or…with the code you already have, you should have something like this and it might work:

    Thread t1 = new Thread(new ThreadStart(
    delegate()
    {
        for (int i = 1; i < 11; i++)
        {
        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
            new Action(delegate()
                {                        
                        mytxt1.Text = "Counter is: " + i.ToString();                           
    
                }));
         Thread.Sleep(1000);
         }             
    }));
    t1.Start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to update some part of a matrix, I got the following error
UPDATE I tried using the internal wordpress rewrite. What I have to do is
I have the following binding in my wpf application xaml: <TextBox Text={Binding Amount, StringFormat=c}
I can display my data in my textbox, dropdownlist after retrieve data from sql
I have also tried .('refresh') and .page() to no avail. The text-box updates but
Is it possible to update first row and with WHERE clause. I Tried: UPDATE
I tried to update an fullcalendar event with updateEvent but only the first time
Our proxy went down and I tried to update dependencies with Maven while it
Hey, I've tried to update jQuery to its latest version on a system I'm
I downloaded a pre-release version of the iPhone SDK and tried to update one

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.