📜 ⬆️ ⬇️

SafeThreadUpdate () for wpf controls

Hi guys! For many, it’s probably inconvenient to contact the Dispatcher every time you need to update the control from a non-UI thread in WPF ... well, I was particularly sick of it, so I wrote a very simple extension-method, which I want to share with you all:

static class exMethods { async public static void ThreadSafeUpdate(this System.Windows.Controls.Control @this, Action updateLogic) { await @this.Dispatcher.BeginInvoke(updateLogic); } } 


It works like this:
 this.ThreadSafeUpdate(() => this.Visibility = Visibility.Hidden); 

')

Source: https://habr.com/ru/post/271781/


All Articles