Skip to content

Instantly share code, notes, and snippets.

@wbokkers
Created November 9, 2022 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbokkers/1bfd808d0728941ea23ec976d9af460b to your computer and use it in GitHub Desktop.
Save wbokkers/1bfd808d0728941ea23ec976d9af460b to your computer and use it in GitHub Desktop.
How to use IAsyncOperationWithProgress
async Task InstallWithAppInstaller()
{
var pm = new PackageManager();
var volume = pm.GetDefaultPackageVolume();
var operationWithProgress = pm.AddPackageByAppInstallerFileAsync(new Uri("https://<the app installer location>"),
AddPackageByAppInstallerOptions.None, volume);
operationWithProgress.Progress = ReportProgress;
var result = await operationWithProgress;
// NOTE: Sometimes you will see AsTask(progress) as an alternative.
// I've found this won't work as expected: on many occasions the task never completes.
}
private void ReportProgress(IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> _, DeploymentProgress progress)
{
Debug.WriteLine(progress.state + " " + progress.percentage + "%");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment