Langage

JoinableTaskFactory.Run Méthode

Définition

Surcharges

Nom Description
Run(Func<Task>)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de façon synchrone le thread appelant.

Run(Func<Task>, JoinableTaskCreationOptions)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de façon 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 façon synchrone le thread appelant.

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

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de façon synchrone le thread appelant.

Run(Func<Task>)

Exécute la méthode asynchrone spécifiée pour terminer tout en bloquant de façon 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 rethrown 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 consiste à reprendre dans son contexte d’origine en tant qu’exécution de méthode asynchrone ordinaire. Par exemple, si l’appelant était sur le thread principal, l’exécution reprend après une attente sur le thread principal ; mais s’il a démarré sur un thread de thread, il reprend sur un thread threadpool.

// 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 façon 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

Utilisé JoinableTaskCreationOptions 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 façon 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

Utilisé JoinableTaskCreationOptions 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 rethrown 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 consiste à reprendre dans son contexte d’origine en tant qu’exécution de méthode asynchrone ordinaire. Par exemple, si l’appelant était sur le thread principal, l’exécution reprend après une attente sur le thread principal ; mais s’il a démarré sur un thread de thread, il reprend sur un thread threadpool.

// 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 façon 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 rethrown 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 consiste à reprendre dans son contexte d’origine en tant qu’exécution de méthode asynchrone ordinaire. Par exemple, si l’appelant était sur le thread principal, l’exécution reprend après une attente sur le thread principal ; mais s’il a démarré sur un thread de thread, il reprend sur un thread threadpool.

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

S’applique à