Graphics Reference
In-Depth Information
7.
By incorporating some XAML on the
MainPage.xaml
to show a loading screen or
menu, we can keep our application responsive while the resources continue to load.
The following screenshot shows a simple example running in the Windows Store app
device simulator:
Running in simulator—top: showing loading message while compiling shaders and loading meshes.
How it works…
The
async
and
await
keywords are a language construct that leverages asynchronous
support in the .NET Framework 4.5. By using the
async
modifier, you specify that a method,
lambda expression, or anonymous method is asynchronous. The
await
operator on the other
hand, is applied to a task in an asynchronous method (a method decorated with the
async
modifier) in order to suspend the execution of the method until the awaited task is completed.
In the previous recipe, where we were initializing the
D3DApp
instance within the constructor,
the
CreateDeviceDependentResources
event handler ends up running synchronously
regardless of the
async
/
await
commands used. By moving this initialization out of
the constructor and into the
Loaded
event, we are then able to take advantage of an
asynchronous implementation.