Created
November 9, 2022 11:53
-
-
Save wbokkers/1bfd808d0728941ea23ec976d9af460b to your computer and use it in GitHub Desktop.
How to use IAsyncOperationWithProgress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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