Share via


JoinableTaskFactory.Run Méthode

Définition

Surcharges

Run(Func<Task>)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

Run(Func<Task>, JoinableTaskCreationOptions)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

Run<T>(Func<Task<T>>, JoinableTaskCreationOptions)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

Run<T>(Func<Task<T>>)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

Run(Func<Task>)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

public:
 void Run(Func<System::Threading::Tasks::Task ^> ^ asyncMethod);
public void Run (Func<System.Threading.Tasks.Task> asyncMethod);
member this.Run : Func<System.Threading.Tasks.Task> -> unit
Public Sub Run (asyncMethod As Func(Of Task))

Paramètres

asyncMethod
Func<Task>

Méthode asynchrone à exécuter.

Remarques

Toute exception levée par le délégué est réinjectée dans son type d’origine à l’appelant de cette méthode.

Lorsque le délégué reprend à partir d’une attente de rendement, le comportement par défaut est de reprendre dans son contexte d’origine comme le ferait une exécution de méthode asynchrone ordinaire. Par exemple, si l’appelant se trouvait sur le thread main, l’exécution reprend après une attente sur le main thread ; mais si elle a démarré sur un thread de thread de thread, elle reprend sur un thread de thread de thread.

// On threadpool or Main thread, this method will block
// the calling thread until all async operations in the
// delegate complete.
joinableTaskFactory.Run(async delegate {
    // still on the threadpool or Main thread as before.
    await OperationAsync();
    // still on the threadpool or Main thread as before.
    await Task.Run(async delegate {
         // Now we're on a threadpool thread.
         await Task.Yield();
         // still on a threadpool thread.
    });
    // Now back on the Main thread (or threadpool thread if that's where we started).
});

S’applique à

Run(Func<Task>, JoinableTaskCreationOptions)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

public:
 void Run(Func<System::Threading::Tasks::Task ^> ^ asyncMethod, Microsoft::VisualStudio::Threading::JoinableTaskCreationOptions creationOptions);
public void Run (Func<System.Threading.Tasks.Task> asyncMethod, Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions creationOptions);
member this.Run : Func<System.Threading.Tasks.Task> * Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions -> unit
Public Sub Run (asyncMethod As Func(Of Task), creationOptions As JoinableTaskCreationOptions)

Paramètres

asyncMethod
Func<Task>

Méthode asynchrone à exécuter.

creationOptions
JoinableTaskCreationOptions

JoinableTaskCreationOptions utilisé pour personnaliser le comportement de la tâche.

S’applique à

Run<T>(Func<Task<T>>, JoinableTaskCreationOptions)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

public:
generic <typename T>
 T Run(Func<System::Threading::Tasks::Task<T> ^> ^ asyncMethod, Microsoft::VisualStudio::Threading::JoinableTaskCreationOptions creationOptions);
public T Run<T> (Func<System.Threading.Tasks.Task<T>> asyncMethod, Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions creationOptions);
member this.Run : Func<System.Threading.Tasks.Task<'T>> * Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions -> 'T
Public Function Run(Of T) (asyncMethod As Func(Of Task(Of T)), creationOptions As JoinableTaskCreationOptions) As T

Paramètres de type

T

Type de valeur retourné par l'opération asynchrone.

Paramètres

asyncMethod
Func<Task<T>>

Méthode asynchrone à exécuter.

creationOptions
JoinableTaskCreationOptions

JoinableTaskCreationOptions utilisé pour personnaliser le comportement de la tâche.

Retours

T

Résultat de la tâche retournée par asyncMethod.

Remarques

Toute exception levée par le délégué est réinjectée dans son type d’origine à l’appelant de cette méthode.

Lorsque le délégué reprend à partir d’une attente de rendement, le comportement par défaut est de reprendre dans son contexte d’origine comme le ferait une exécution de méthode asynchrone ordinaire. Par exemple, si l’appelant se trouvait sur le thread main, l’exécution reprend après une attente sur le main thread ; mais si elle a démarré sur un thread de thread de thread, elle reprend sur un thread de thread de thread.

// On threadpool or Main thread, this method will block
// the calling thread until all async operations in the
// delegate complete.
joinableTaskFactory.Run(async delegate {
    // still on the threadpool or Main thread as before.
    await OperationAsync();
    // still on the threadpool or Main thread as before.
    await Task.Run(async delegate {
         // Now we're on a threadpool thread.
         await Task.Yield();
         // still on a threadpool thread.
    });
    // Now back on the Main thread (or threadpool thread if that's where we started).
});

S’applique à

Run<T>(Func<Task<T>>)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de manière synchrone le thread appelant.

public:
generic <typename T>
 T Run(Func<System::Threading::Tasks::Task<T> ^> ^ asyncMethod);
public T Run<T> (Func<System.Threading.Tasks.Task<T>> asyncMethod);
member this.Run : Func<System.Threading.Tasks.Task<'T>> -> 'T
Public Function Run(Of T) (asyncMethod As Func(Of Task(Of T))) As T

Paramètres de type

T

Type de valeur retourné par l'opération asynchrone.

Paramètres

asyncMethod
Func<Task<T>>

Méthode asynchrone à exécuter.

Retours

T

Résultat de la tâche retournée par asyncMethod.

Remarques

Toute exception levée par le délégué est réinjectée dans son type d’origine à l’appelant de cette méthode.

Lorsque le délégué reprend à partir d’une attente de rendement, le comportement par défaut est de reprendre dans son contexte d’origine comme le ferait une exécution de méthode asynchrone ordinaire. Par exemple, si l’appelant se trouvait sur le thread main, l’exécution reprend après une attente sur le main thread ; mais si elle a démarré sur un thread de thread de thread, elle reprend sur un thread de thread de thread.

Consultez la documentation sur la Run(Func<Task>) surcharge pour obtenir un exemple.

S’applique à