JoinableTaskFactory.Run Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
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
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
- 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
- creationOptions
- JoinableTaskCreationOptions
Utilisé JoinableTaskCreationOptions pour personnaliser le comportement de la tâche.
Retours
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
Retours
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.