Partager via


IAsyncServiceProvider.GetServiceAsync(Type) Method

Definition

Retrieves a proffered service asynchronously.

public:
 System::Threading::Tasks::Task<System::Object ^> ^ GetServiceAsync(Type ^ serviceType);
public System.Threading.Tasks.Task<object> GetServiceAsync (Type serviceType);
public System.Threading.Tasks.Task<object?> GetServiceAsync (Type serviceType);
abstract member GetServiceAsync : Type -> System.Threading.Tasks.Task<obj>
Public Function GetServiceAsync (serviceType As Type) As Task(Of Object)

Parameters

serviceType
Type

The service identity of the proffered service to retrieve.

Returns

A task whose result is one of the following:

  • The service if the request was successful.
  • null if the service threw an exception during activation.
  • null if the associated package failed to load.
  • null if the associated package proffered null.
  • null if the associated package could not be found, or the package did not correctly proffer the service.
  • null if the environment has starting shutting down and the retrieval would have resulted in a package load.
  • Otherwise; null if there was any other failure retrieving the service.

Exceptions

serviceType is null.

Remarks

Performing an explicit cast of the resulting service to a specific interface could perform a blocking RPC call if the underlying service is STA-bound, which can hang if the UI thread is blocked in a Run(Func<Task>) or Join(CancellationToken). Instead, prefer the generic equivalents GetServiceAsync<TService,TInterface>(Boolean, CancellationToken) and Microsoft.VisualStudio.Shell.ServiceExtensions.GetServiceAsync, noting the difference in behavior around exceptions.

This method is safe to access from any thread.

Applies to