For the last 10 years, I was using WPF with the "Dispatcher" in order to ensure UI thread will receive notifications. I was using code like this in a base "Model" class:
[NotifyPropertyChangedInvocator]
public void RaisePropertyChanged([CallerMemberName] String propertyName = "")
{
var propertyChanged = PropertyChanged;
if (propertyChanged != null)
{
if (Dispatcher == null) // For console App
{
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
else
{
if (Dispatcher.CheckAccess())
{
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
else
{
Dispatcher.Invoke(new Action(() => propertyChanged(this, new PropertyChangedEventArgs(propertyName))));
}
}
}
}
In this SO Question, some talk about AsynContext, another seems to add nuget package "Microsoft.NET.Sdk.WindowsDesktop" which seems to be Windows OS dependant.
What is the recommended way to do the equivalent in new Desktop application? Where is the Dispatcher? Is there any equivalent? Can we keep our code OS independant? Should we wait few months more until Microsoft will come with an OS independant solution?