fully utilize C# async await

is possible utilize C# async await in monogame?

Should be, but how do you mean?

You can do the following without problems. You will however run into issues with UI Thread synchronization trying to use ContinueWith.

    protected override async void Draw(GameTime gameTime)

        await SomeTask();
        await SomeTask2();

        Task.WaitAny(new Task[] { SomeTask(), SomeTask2() });


yes it works, tasks work too, threads work too, but be careful of stalls

There are no awaitable APIs in MonoGame (yet), but you can definitely use async/await in your code. That is up to the C# compiler and framework you use, and I believe all the available options support async/await now.

Got it, Thanks for reply.:grinning:

Id be cautious of this async in draw ! Is that really a smart idea ?

Async in Draw() is definitely not recommended. Having said that async/await is usable, you still have to be very careful about interaction between updates and draws.

is possible to make update & draw run parallel ?

It is possible. The Draw() should be left on the thread it is on, and the update of your game state could be done on another thread. You must be very careful with data that is shared between the update and draw though. The update thread cannot modify the data that the draw thread is using. One way of doing this is to have the update thread create a draw list. When the two threads are synchronized, i.e. an update has completed and it is about to do a draw, the draw list is moved to the draw function and the update thread begins to populate another draw list for the next frame. At the next synchronization, the two draw lists are swapped so the draw thread draws the new list and the update re-populates the other draw list.

We use async/await as a coroutine mechanism, which works well for games and means you don’t need to worry about threading. If anyone is interested, the implementation is here: https://github.com/RedpointGames/Protogame/tree/master/Protogame/Coroutine. To adapt it for your own stuff, just copy the “Run” functions for when you want to start running a coroutine, and change the private Update method on the scheduler to public and call it at the start of every game update.