How use async API in UWP (XAML) project with Monogame 3.8

Hello. I’ve problem with calling async API (for example Windows.System.Launcher.LaunchUriAsync) in Monogame 3.8 (UWP, XAML). API works in Initialize method but doesn’t work in Update. I think, it relates with work in different threads.
I checked calling API in UWP (XAML) with 3.7 and Desktop and UWP (CoreApp) projects with 3.8 version of Monogame - API works well.
Where is my fault?
How should I call API in UWP (XAML)?

Hey @Denis_S, Welcome to the Community!

While I may not be correct but you cannot thread the Update calls and the Draw calls together…

I will be keeping track of this and if no further help, I will play with it myself specifically for data handling.

Happy Coding!

According to the Microsoft docs (https://docs.microsoft.com/en-us/uwp/api/windows.system.launcher.launchuriasync) “this API must be called from within an ASTA thread”.

To achieve this change this code:

await Windows.System.Launcher.LaunchUriAsync(new Uri("https://www.monogame.net"));

To this:

await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
    Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { await Windows.System.Launcher.LaunchUriAsync(new Uri("https://www.monogame.net")); });

Hope that helps.

1 Like

It works. Thanks.

1 Like