How can I use class System.Windows.Threading.Dispatcher from within a .Net 5.0 app?
According to the online documentation, it should be available.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatcher?view=net-5.0.
Normally, in a .Net Framework app, I would just add a reference to assembly WindowsBase.dll. But since I'm using a .Net 5.0 project I can only reference Nuget Packages.
Cannot add assemblies to .Net Core application in Visual Studio 2019.
However, there does not seem to be a WindowsBase Nuget package.
https://www.nuget.org/packages?q=WindowsBase.
There is a package called Microsoft.Windows.Compatibility which according to its descriptions sounds like it should include the class; but it does not.
https://www.nuget.org/packages/Microsoft.Windows.Compatibility/6.0.0-preview.5.21301.5
Any suggestions?
Restrictions:
After looking carefully, I realized that as of today (17/Jun/2021) The Nuget Package Microsoft.Windows.Compatibility is still in pre-release. This means that by the time other people read this thread the class might be already included.
If not, I found a workaround:
However, after reading the comment from Jimi, I think that, when working on a Winforms application, it is more elegant to use SynchronizationContext instead of Dispatcher.