Skip to content

Commit 1f7397e

Browse files
committed
Ensure IServiceBroker is used on a background thread
Expands #47903 to other calls to GetProxyAsync.
1 parent de348c5 commit 1f7397e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ private async Task ProcessWorkQueueWorkerAsync(
456456
if (serviceBroker == null)
457457
return;
458458

459+
// Make sure we are on the thread pool to avoid UI thread dependencies if external code uses ConfigureAwait(true)
460+
await TaskScheduler.Default;
461+
459462
var nugetService = await serviceBroker.GetProxyAsync<INuGetProjectService>(NuGetServices.NuGetProjectServiceV1, cancellationToken: cancellationToken).ConfigureAwait(false);
460463

461464
using (nugetService as IDisposable)

src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.CodeAnalysis.Serialization;
2020
using Microsoft.CodeAnalysis.TodoComments;
2121
using Microsoft.ServiceHub.Framework;
22+
using Microsoft.VisualStudio.Threading;
2223
using Nerdbank.Streams;
2324
using Roslyn.Test.Utilities;
2425
using Roslyn.Utilities;
@@ -116,6 +117,9 @@ public override async ValueTask<RemoteServiceConnection<T>> CreateConnectionAsyn
116117
var assetStorage = _workspaceServices.GetRequiredService<ISolutionAssetStorageProvider>().AssetStorage;
117118
var descriptor = ServiceDescriptors.GetServiceDescriptor(typeof(T), isRemoteHost64Bit: IntPtr.Size == 8);
118119

120+
// Make sure we are on the thread pool to avoid UI thread dependencies if external code uses ConfigureAwait(true)
121+
await TaskScheduler.Default;
122+
119123
#pragma warning disable ISB001 // Dispose of proxies - caller disposes
120124
var proxy = await _inprocServices.ServiceBroker.GetProxyAsync<T>(descriptor, options, cancellationToken).ConfigureAwait(false);
121125
#pragma warning restore

src/Workspaces/Remote/ServiceHub/Host/SolutionAssetSource.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Threading.Tasks;
1212
using Microsoft.CodeAnalysis.Serialization;
1313
using Microsoft.ServiceHub.Framework;
14+
using Microsoft.VisualStudio.Threading;
1415
using Roslyn.Utilities;
1516

1617
namespace Microsoft.CodeAnalysis.Remote
@@ -28,6 +29,9 @@ public SolutionAssetSource(ServiceBrokerClient client, CancellationTokenSource c
2829

2930
public async ValueTask<ImmutableArray<(Checksum, object)>> GetAssetsAsync(int scopeId, ISet<Checksum> checksums, ISerializerService serializerService, CancellationToken cancellationToken)
3031
{
32+
// Make sure we are on the thread pool to avoid UI thread dependencies if external code uses ConfigureAwait(true)
33+
await TaskScheduler.Default;
34+
3135
using var provider = await _client.GetProxyAsync<ISolutionAssetProvider>(SolutionAssetProvider.ServiceDescriptor, cancellationToken).ConfigureAwait(false);
3236
Contract.ThrowIfNull(provider.Proxy);
3337

@@ -39,6 +43,9 @@ public SolutionAssetSource(ServiceBrokerClient client, CancellationTokenSource c
3943

4044
public async ValueTask<bool> IsExperimentEnabledAsync(string experimentName, CancellationToken cancellationToken)
4145
{
46+
// Make sure we are on the thread pool to avoid UI thread dependencies if external code uses ConfigureAwait(true)
47+
await TaskScheduler.Default;
48+
4249
using var provider = await _client.GetProxyAsync<ISolutionAssetProvider>(SolutionAssetProvider.ServiceDescriptor, cancellationToken).ConfigureAwait(false);
4350
Contract.ThrowIfNull(provider.Proxy);
4451

0 commit comments

Comments
 (0)