How to implement IAsyncOperationWithProgress

Here is an example of using IAsyncOperationWithProgress to display the progress of installing an XAP file programatically. I'm pretty new to Win8 development so not sure if it's entirely idiomatic.

Note the Dispatcher.BeginInvoke to marshall the progress back to the UI thread. Hope it helps:

private async void InstallApp(string name, Uri uri)
{
    try
    {
        StatusTextBlock.Text = "Installing app";
        var installTask = InstallationManager.AddPackageAsync(name, uri);

        installTask.Progress = (installResult, progress) => Dispatcher.BeginInvoke(() =>
        {
            StatusTextBlock.Text = "Progress: " + progress;
        });

        var result = await installTask;
        StatusTextBlock.Text = "Done: " + result.InstallState.ToString();
    }
    catch (Exception ex)
    {
        StatusTextBlock.Text = "Failed to install: " + ex.Message;
    }
}