CanvasCreateResourcesEventArgsTrackAsyncAction Method |
Namespace: Microsoft.Graphics.Canvas.UI
public void TrackAsyncAction( IAsyncAction action )
Use this when creating resources involves asynchronous method calls, such as CanvasBitmap.LoadAsync.
void Canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args) { args.TrackAsyncAction(Canvas_CreateResourcesAsync(sender).AsAsyncAction()); } async Task Canvas_CreateResourcesAsync(CanvasControl sender) { bitmapTiger = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg"); }
Using TrackAsyncAction will:
For more advanced asynchronous loading scenarios, see this article.
In the current implementation, only one action per control can be tracked at a time. Attempting to track multiple actions simultaneously will cause TrackAsyncAction to throw an exception.
The behavior discussed above pertains to CanvasCreateResourcesEventArgs passed to an app through its CreateResources event handler.
For instances of CanvasCreateResourcesEventArgs which the app has created itself, TrackAsyncAction is a lightweight operation which does not do the above behavior. It holds a reference to the tracked action which can be retrieved using GetTrackedAction.