-3

I googled now for a lot of days including stackoverflow itself, but I still can't find any working solution for my purposes. I'm Beginner with WPF and just want to update control contents during runtime in real time and not after the function is finish executed (after 5 seconds through the sleep). I attached the small project for testing... Any help to get it to work would be highly appreciated! :(

Many thanks and have a nice weekend!

Link to File (OneDrive): https://1drv.ms/u/s!Ah_jzGa_zAzHgg5f_FEm3ERzRhfa?e=0Kkrog

enter image description here

Dave
  • 19
  • 4

1 Answers1

0

Thread.Sleep() will block the main UI, so in your case even if the UI is already updated, you won't be able to see it.

I guess you can do MainWindow.Instance.Invalidate() before calling Thread.Sleep()

Saad Shaikh
  • 175
  • 1
  • 13
  • 1
    Besides that there neither is an `Instance` property nor an `Invalide()` method in the WPF Window class, you would never call `Thread.Sleep` at all in a UI application. – Clemens Aug 12 '22 at 14:38
  • Look at the screenshot, he has the `static` property called `Instance`. I guess we can call `form.Invalidate()` – Saad Shaikh Aug 12 '22 at 14:43
  • Invalidate is not a WPF method. This is not WinForms, so you are guessing wrong. While there are equivalent methods in WPF, you would just not use them in this scenario. Just don't call Sleep. – Clemens Aug 12 '22 at 14:44
  • Your comments redirected me to the right way; thanks a lot!! I really need to learn more about threading etc. – Dave Aug 15 '22 at 09:38