I searched for a reason, but about every topic in stackoverflow that I could find was suggested as a reason for a busy user interface. I have very simple code, just for testing, and it just wonβt update the user interface, although Iβm sure that it cannot be occupied with 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 for updating textBlock1.Text , and it was interrupted every 5 seconds, but the user interface was never updated. As the code shows , when I move the mouse over the Button , I use to start the timer, the button shows its typical mouse-over-button animation. . Why is this happening but not updating the text?
If someone can lead me to a good topic in stackoverflow, do it and I will delete my question here, but I could not find a single topic explaining why this approach does not update the user interface, even if the user interface is not busy doing something else.
source share