If Update and Draw both trigger the same event, but differentiated using different cases of a Discriminated Union, we can safely await the single event, and act appropriately. Luckily the excellent Monogame project has picked up Microsoft’s slack and put XNA on Mac, Linux, i OS, Android, PS Vita, Windows 8, and more.I remember back in the late 90’s writing Direct X 7 code in C++ and the ridiculous amount of boilerplate associated with it – setting up a Win32 Window, initialising Direct Draw, initialising Direct3D, doing voodoo incantations and maybe after a couple of hours of tinkering you’d have an empty window. Content The add Line async workflow is where the magic happens – we await our 1st triggering event (in this case a mouse down), capture some information, then await our exiting event (in this case a mouse up), perform the action (draw the line), then do start again.You’ll need to install XNA before trying to create a new application in VS. But we can add them, and trigger them at the keys points – Initialise, Load Content, and then in a loop over Update and Draw. Features such as F# async empower developers to find ways to tame the accidental complexity, introduced by external frameworks such as XNA or WPF.Upon creating a new project using that template, you’re going to see a simple XNA Game implementation, using idiomatic XNA conventions. We can then expose the events as async Workflows, and then consume the game logic entirely outside the XNA Game implementation.
XNA just made it easy to create a new project and start writing a game in . Threading type Drawing Window() as window = inherit Window() let canvas = Canvas(Horizontal Alignment=Horizontal Alignment. The C# equivalent, would likely have ended up capturing the intermediate state between events a class level mutable fields, or worse, some shoehorned in Rx “goodness”.But, as good as XNA is, it’s still rooted in mid-noughties Microsoft OO conventions. One of the most common misconceptions I hear about async (in both C# and F#) is that it’s about threads – I prefer describe it as simply “non-blocking” – notice this WPF example has nothing to do with threads, despite relying on async. game Loop 0.f 0.f 4.f 4.f } game Workflow | And with that we’re done.