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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:46:54+00:00 2026-06-13T12:46:54+00:00

I have been looking for a reason, but about every single topic on stackoverflow

  • 0

I have been looking for a reason, but about every single topic on stackoverflow I could find suggested a busy UI as the reason.
I have very basic code, just for testings and it simply won’t update the UI, even though I am sure it cannot be busy doing something else:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    static double t = 0;
    static double dt = 0.1;

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        Timer timer = new Timer(5000);
        timer.Enabled = true;
        timer.Elapsed += new ElapsedEventHandler(Update);
        timer.Start();
    }

    void Update(object sender, ElapsedEventArgs e)
    {
        t = t + dt;
        testBlock1.Text = (t).ToString();
    }
}

I debugged it and set a breakpoint to the textBlock1.Text update and it did break every 5 seconds, but the UI is never updated. As can be seen in the code, when I move my mouse over the Button I use to start the timer, the button shows its typical “mouse-over-button” animation. Why does that happen, but not the text update?

If anyone can lead me to a good topic on stackoverflow, please do so and I will delete my question here, but I couldn’t find any topic explaining why this approach doesn’t update the UI even though the UI is not busy doing anyting else.

  • 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-13T12:46:55+00:00Added an answer on June 13, 2026 at 12:46 pm

    For WPF, you should use DispatcherTimer –
    Also with the above code you posted, i am getting a cross thread error since elapsed event is raised on other thread and not on UI thread.

    private void button1_Click(object sender, RoutedEventArgs e)
    {
       DispatcherTimer timer = new DispatcherTimer();
       timer.Interval = new TimeSpan(0, 0, 5);
       timer.Tick += new EventHandler(timer_Tick);
       timer.Start();
    }
    
    void timer_Tick(object sender, EventArgs e)
    {
       t = t + dt;
       txt.Text = (t + dt).ToString();
    }
    

    EDIT

    Also, you can marshal it on UI Dispatcher with your existing code like this –

    void Update(object sender, ElapsedEventArgs e)
    {
        App.Current.Dispatcher.Invoke((Action)delegate()
        {
            t = t + dt;
            txt.Text = (t + dt).ToString();
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I have been looking about but can not for the wits of me
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking online to find documentation for the function in QTP and
I have been looking for an answer to this on Stack Overflow, but I
I have been looking at this forum on this topic for a while now
I have been looking for an alternative to Hibernate for various reasons. I came
I have been looking around for a visualization framework that would aid graph visualization
I have been looking into AWS spot instances for some jobs however instead of
I have been looking into backbone.js and I can't seem to figure out how
I have been looking at the Thinktecture.IdentityModel.40 library as a way of handling the

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.