Share via


JoinableTaskFactory.Run Metodo

Definizione

Overload

Run(Func<Task>)

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

Run(Func<Task>, JoinableTaskCreationOptions)

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

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

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

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

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

Run(Func<Task>)

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

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

Parametri

asyncMethod
Func<Task>

Il metodo asincrono da eseguire.

Commenti

Qualsiasi eccezione generata dal delegato viene generata nuovamente nel tipo originale al chiamante di questo metodo.

Quando il delegato riprende da un'attesa di rendimento, il comportamento predefinito consiste nel riprendere nel contesto originale come un'esecuzione normale del metodo asincrono. Ad esempio, se il chiamante si trovava nel thread principale, l'esecuzione riprende dopo un'attesa nel thread principale; ma se è stato avviato in un thread del pool di thread, riprende in un thread del pool di 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).
});

Si applica a

Run(Func<Task>, JoinableTaskCreationOptions)

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

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)

Parametri

asyncMethod
Func<Task>

Il metodo asincrono da eseguire.

creationOptions
JoinableTaskCreationOptions

Oggetto JoinableTaskCreationOptions usato per personalizzare il comportamento dell'attività.

Si applica a

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

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

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

Parametri di tipo

T

Il tipo di valore restituito dall'operazione asincrona.

Parametri

asyncMethod
Func<Task<T>>

Il metodo asincrono da eseguire.

creationOptions
JoinableTaskCreationOptions

Oggetto JoinableTaskCreationOptions usato per personalizzare il comportamento dell'attività.

Restituisce

T

Risultato dell'attività restituita da asyncMethod.

Commenti

Qualsiasi eccezione generata dal delegato viene generata nuovamente nel tipo originale al chiamante di questo metodo.

Quando il delegato riprende da un'attesa di rendimento, il comportamento predefinito consiste nel riprendere nel contesto originale come un'esecuzione normale del metodo asincrono. Ad esempio, se il chiamante si trovava nel thread principale, l'esecuzione riprende dopo un'attesa nel thread principale; ma se è stato avviato in un thread del pool di thread, riprende in un thread del pool di 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).
});

Si applica a

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

Esegue il metodo asincrono specificato fino al completamento durante il blocco sincrono del thread chiamante.

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

Parametri di tipo

T

Il tipo di valore restituito dall'operazione asincrona.

Parametri

asyncMethod
Func<Task<T>>

Il metodo asincrono da eseguire.

Restituisce

T

Risultato dell'attività restituita da asyncMethod.

Commenti

Qualsiasi eccezione generata dal delegato viene generata nuovamente nel tipo originale al chiamante di questo metodo.

Quando il delegato riprende da un'attesa di rendimento, il comportamento predefinito consiste nel riprendere nel contesto originale come un'esecuzione normale del metodo asincrono. Ad esempio, se il chiamante si trovava nel thread principale, l'esecuzione riprende dopo un'attesa nel thread principale; ma se è stato avviato in un thread del pool di thread, riprende in un thread del pool di thread.

Per un esempio, vedere la documentazione sull'overload Run(Func<Task>) .

Si applica a