private static async Task WriteNuGetDownloadsAsync() { string packageId = "Microsoft.Bcl.AsyncInterfaces"; Task <int> task = NuGetService.GetAsync(packageId, true, default); int totalDownloads = await task; Console.WriteLine($"NuGet package '{packageId}' has {totalDownloads} total downloads"); }
private async void OnGetDownloads(object sender, RoutedEventArgs e) { string packageId = PackageId.Text; Task <int> task = NuGetService.GetAsync(packageId, true, cts.Token); try { int totalDownloads = await task.ConfigureAwait(false); await this; TotalDownloads.Text = $"{totalDownloads}"; } catch (OperationCanceledException ex) { await Dispatcher.BeginInvoke((Action)(() => TotalDownloads.Text = ex.Message)); } }