SafeThreadUpdate () for wpf controls
Hi guys! Most probably, it’s inconvenient to contact Dispatcher every time you need to update the control from a non-UI thread in WPF ... in general, I got tired of it, so I wrote a very simple extension method that I want to share with you all:
It works like this:
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);