Skip to content

Commit

Permalink
Fix a code path that calls into CreateCacheFileAsync from running on …
Browse files Browse the repository at this point in the history
…the UI thread.
  • Loading branch information
jebriede committed Jul 27, 2022
1 parent c2fd987 commit c03fc79
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,16 @@ private async ValueTask RefreshInstalledAndUpdatesTabsAsync()

private async Task<(int, int)> GetInstalledVulnerableAndDeprecatedPackagesCountAsync(PackageLoadContext loadContext, CancellationToken token)
{
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
IReadOnlyCollection<PackageSourceContextInfo> packageSources = SelectedSource.PackageSources;

// Switch off the UI thread before fetching installed packages and deprecation metadata.
await TaskScheduler.Default;

PackageCollection installedPackages = await loadContext.GetInstalledPackagesAsync();

var installedPackageMetadata = await Task.WhenAll(
installedPackages.Select(p => GetPackageMetadataAsync(p, token)));
installedPackages.Select(p => GetPackageMetadataAsync(p, packageSources, token)));

int vulnerablePackagesCount = 0;
int deprecatedPackagesCount = 0;
Expand All @@ -975,13 +978,12 @@ private async ValueTask RefreshInstalledAndUpdatesTabsAsync()
return (vulnerablePackagesCount, deprecatedPackagesCount);
}

private async Task<(PackageSearchMetadataContextInfo, PackageDeprecationMetadataContextInfo)> GetPackageMetadataAsync(PackageCollectionItem package, CancellationToken cancellationToken)
private async Task<(PackageSearchMetadataContextInfo, PackageDeprecationMetadataContextInfo)> GetPackageMetadataAsync(PackageCollectionItem package, IReadOnlyCollection<PackageSourceContextInfo> packageSources, CancellationToken cancellationToken)
{
using (INuGetSearchService searchService = await _serviceBroker.GetProxyAsync<INuGetSearchService>(NuGetServices.SearchService, cancellationToken: cancellationToken))
{
Assumes.NotNull(searchService);
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
return await searchService.GetPackageMetadataAsync(package, SelectedSource.PackageSources, true, cancellationToken);
return await searchService.GetPackageMetadataAsync(package, packageSources, true, cancellationToken);
}
}

Expand Down

0 comments on commit c03fc79

Please sign in to comment.