AsyncPackage.InitializeAsync Method

Definition

When overridden in a derived class, asynchronously initializes the package. This method is invoked from a background thread.

protected:
 virtual System::Threading::Tasks::Task ^ InitializeAsync(System::Threading::CancellationToken cancellationToken, IProgress<Microsoft::VisualStudio::Shell::ServiceProgressData ^> ^ progress);
protected virtual System.Threading.Tasks.Task InitializeAsync (System.Threading.CancellationToken cancellationToken, IProgress<Microsoft.VisualStudio.Shell.ServiceProgressData> progress);
abstract member InitializeAsync : System.Threading.CancellationToken * IProgress<Microsoft.VisualStudio.Shell.ServiceProgressData> -> System.Threading.Tasks.Task
override this.InitializeAsync : System.Threading.CancellationToken * IProgress<Microsoft.VisualStudio.Shell.ServiceProgressData> -> System.Threading.Tasks.Task
Protected Overridable Function InitializeAsync (cancellationToken As CancellationToken, progress As IProgress(Of ServiceProgressData)) As Task

Parameters

cancellationToken
CancellationToken

A cancellation token to monitor for initialization cancellation, which will be triggered just before a package is closed during shutdown if the resulting task has not yet completed. This token is distinct to DisposalToken, and tasks that complete after InitializeAsync(CancellationToken, IProgress<ServiceProgressData>) should favor DisposalToken.

Returns

A task representing the asynchronously work of package initialization, or an already completed task if there is none. Do not return null from this method.

Exceptions

cancellationToken has been canceled.

Remarks

The default implementation of this method does nothing and there is no requirement to call it in an override.

InitializeAsync(CancellationToken, IProgress<ServiceProgressData>) should be used to do a very minimal amount of work, such as registering editor factories, project types, brokered services, adding services, initializing command handlers, and hooking onto events. It should not blocking on network requests, scanning disks, requesting MEF components and other long running work. That work should be performed in OnAfterPackageLoadedAsync(CancellationToken), be asynchronous and later joined, or calculated at the point the data it produces is requested.

Applies to