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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:38:24+00:00 2026-05-28T06:38:24+00:00

I have a particular problem with updating a TextBlock with changing values (which will

  • 0

I have a particular problem with updating a TextBlock with changing values (which will eventually be streamed over a network). This is a similar problem to that experienced by others on this forum with the exception that the test solution below works initially (i.e the timer successfully updates the textBlock1.text which then displays correctly) but then fails after a certain number of iterations (usually between 200 and 300). I guess I am doing something wrong with whatever way I am handling the thread.

I am new to C#, .Net and threading so any advice would be greatly appreciated.

namespace TestWPF_WorkerThreads
{
    MainWindow : Window
    {
        private int counter = 0;
        private string counterText="";

        public MainWindow()
        {
            InitializeComponent();
            Timer myTimer = new Timer(Work, counterText, 1000, 100);

        }

        void Work(Object message)
        {
            counter++;
            counterText = counter.ToString();
            string temp = message.ToString();
            temp = temp + counterText;
            Thread.Sleep(100);
            UpdateMessage(temp);
        }

        void UpdateMessage(string msg)
        {
            Action action = () => textBlock1.Text = msg;
            Dispatcher.Invoke(action);

        }
    }
}
  • 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-28T06:38:25+00:00Added an answer on May 28, 2026 at 6:38 am

    You have a timer with a period of 100 milliseconds, and the code which it invokes contains a ‘sleep’ which waits 100 milliseconds. This sounds wrong!

    You should read this excellent article on timers on MSDN, you will see that the System.Threading.Timer which you are using continues to fire regardless of whether you ‘sleep’. With WPF it is much better to use the DispatcherTimer class which fires on the UI thread.

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

Sidebar

Related Questions

My particular problem: I have a string which specifies an aribitrary type in a
i have this problem to find a particular xml node l have post this
This is a particular problem that I have come across many times, but I
I've read other similar questions on this but they don't solve this particular problem.
I am using Struts2 for a web application development. i have this particular problem
I have one particular problem, I have script which should issue bill statement. Now
Hi everyone I have been working on this particular problem for ages by now,plz
I have a problem downloading particular file types by WebClient. So there are no
I have a problem using the Java search function in Eclipse on a particular
I have a problem; I'm using an external library where one particular event has

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.