共用方式為


VsTaskLibraryHelper.RunAsync Method

Definition

Overloads

RunAsync(JoinableTaskFactory, VsTaskRunContext, Func<Task>)

Wraps the invocation of an async method such that it may execute asynchronously, but may potentially be synchronously completed (waited on) in the future.

RunAsync<T>(JoinableTaskFactory, VsTaskRunContext, Func<Task<T>>)

Wraps the invocation of an async method such that it may execute asynchronously, but may potentially be synchronously completed (waited on) in the future.

RunAsync(JoinableTaskFactory, VsTaskRunContext, Func<Task>)

Wraps the invocation of an async method such that it may execute asynchronously, but may potentially be synchronously completed (waited on) in the future.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::VisualStudio::Threading::JoinableTask ^ RunAsync(Microsoft::VisualStudio::Threading::JoinableTaskFactory ^ joinableTaskFactory, Microsoft::VisualStudio::Shell::VsTaskRunContext priority, Func<System::Threading::Tasks::Task ^> ^ asyncMethod);
public static Microsoft.VisualStudio.Threading.JoinableTask RunAsync (this Microsoft.VisualStudio.Threading.JoinableTaskFactory joinableTaskFactory, Microsoft.VisualStudio.Shell.VsTaskRunContext priority, Func<System.Threading.Tasks.Task> asyncMethod);
static member RunAsync : Microsoft.VisualStudio.Threading.JoinableTaskFactory * Microsoft.VisualStudio.Shell.VsTaskRunContext * Func<System.Threading.Tasks.Task> -> Microsoft.VisualStudio.Threading.JoinableTask
<Extension()>
Public Function RunAsync (joinableTaskFactory As JoinableTaskFactory, priority As VsTaskRunContext, asyncMethod As Func(Of Task)) As JoinableTask

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<Task>

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

Returns

An object that tracks the completion of the async operation, and allows for later synchronous blocking of the main thread for completion if necessary.

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(CancellationToken) if the main thread is desired.

Applies to

RunAsync<T>(JoinableTaskFactory, VsTaskRunContext, Func<Task<T>>)

Wraps the invocation of an async method such that it may execute asynchronously, but may potentially be synchronously completed (waited on) in the future.

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

Type Parameters

T

The type of value returned by the asynchronous 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<Task<T>>

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

Returns

An object that tracks the completion of the async operation, and allows for later synchronous blocking of the main thread for completion if necessary.

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(CancellationToken) if the main thread is desired.

Applies to