Udostępnij za pośrednictwem


VsTaskLibraryHelper.RunAsyncAsVsTask<T> Method

Definition

Creates an IVsTask to track a cancelable async operation.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static Microsoft::VisualStudio::Shell::Interop::IVsTask ^ RunAsyncAsVsTask(Microsoft::VisualStudio::Threading::JoinableTaskFactory ^ joinableTaskFactory, Microsoft::VisualStudio::Shell::VsTaskRunContext priority, Func<System::Threading::CancellationToken, System::Threading::Tasks::Task<T> ^> ^ asyncMethod);
public static Microsoft.VisualStudio.Shell.Interop.IVsTask RunAsyncAsVsTask<T> (this Microsoft.VisualStudio.Threading.JoinableTaskFactory joinableTaskFactory, Microsoft.VisualStudio.Shell.VsTaskRunContext priority, Func<System.Threading.CancellationToken,System.Threading.Tasks.Task<T>> asyncMethod);
static member RunAsyncAsVsTask : Microsoft.VisualStudio.Threading.JoinableTaskFactory * Microsoft.VisualStudio.Shell.VsTaskRunContext * Func<System.Threading.CancellationToken, System.Threading.Tasks.Task<'T>> -> Microsoft.VisualStudio.Shell.Interop.IVsTask
<Extension()>
Public Function RunAsyncAsVsTask(Of T) (joinableTaskFactory As JoinableTaskFactory, priority As VsTaskRunContext, asyncMethod As Func(Of CancellationToken, Task(Of T))) As IVsTask

Type Parameters

T

The type of value returned by the async operation.

Parameters

joinableTaskFactory
JoinableTaskFactory

The factory to use for creating the task.

priority
VsTaskRunContext

The priority with which to schedule any work on the UI thread, when and if SwitchToMainThreadAsync(CancellationToken) is called.

asyncMethod
Func<CancellationToken,Task<T>>

The method that, when executed, will begin the async operation.

Returns

An IVsTask instance.

Remarks

Exceptions thrown by the delegate are captured by the returned JoinableTask. Note that the asyncMethod delegate begins its execution on the caller's thread, and must explicitly call SwitchToMainThreadAsync if the main thread is desired.

Applies to