Search code examples
c#wpfdelegatesinvokedispatcher

WPF - Update GUI in different, static class without delay


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


Solution

  • 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()