Task<TResult> Task<TResult> Task<TResult> Task<TResult> Class

Definición

Representa una operación asincrónica que puede devolver un valor.Represents an asynchronous operation that can return a value.

generic <typename TResult>
public ref class Task : System::Threading::Tasks::Task
public class Task<TResult> : System.Threading.Tasks.Task
type Task<'Result> = class
    inherit Task
Public Class Task(Of TResult)
Inherits Task

Parámetros de tipo

TResult

El tipo del resultado generado por Task<TResult>.The type of the result produced by this Task<TResult>.

Herencia
Task<TResult>Task<TResult>Task<TResult>Task<TResult>

Comentarios

La Task<TResult> clase representa una única operación que devuelve un valor y que normalmente se ejecuta de forma asincrónica.The Task<TResult> class represents a single operation that returns a value and that usually executes asynchronously. Task<TResult> los objetos son uno de los componentes centrales de la modelo asincrónico basado en tareas por primera vez en .NET Framework 4.Task<TResult> objects are one of the central components of the task-based asynchronous pattern first introduced in the .NET Framework 4. Dado que el trabajo realizado por un Task<TResult> objeto normalmente ejecuta de forma asincrónica en un subproceso ThreadPool en lugar de forma sincrónica en el subproceso principal de la aplicación, puede usar el Status propiedad, así como el IsCanceled, IsCompleted, y IsFaulted propiedades para determinar el estado de una tarea.Because the work performed by a Task<TResult> object typically executes asynchronously on a thread pool thread rather than synchronously on the main application thread, you can use the Status property, as well as the IsCanceled, IsCompleted, and IsFaulted properties, to determine the state of a task. Normalmente, se utiliza una expresión lambda para especificar el trabajo que debe realizar la tarea.Most commonly, a lambda expression is used to specify the work that the task is to perform.

Task<TResult> pueden crearse instancias en una variedad de formas.Task<TResult> instances may be created in a variety of ways. El enfoque más común, que está disponible a partir de la .NET Framework 4.5.NET Framework 4.5, consiste en llamar a estático Task.Run<TResult>(Func<TResult>) o Task.Run<TResult>(Func<TResult>, CancellationToken) método.The most common approach, which is available starting with the .NET Framework 4.5.NET Framework 4.5, is to call the static Task.Run<TResult>(Func<TResult>) or Task.Run<TResult>(Func<TResult>, CancellationToken) method. Estos métodos proporcionan una manera sencilla de iniciar una tarea mediante el uso de los valores predeterminados y sin adquirir parámetros adicionales.These methods provide a simple way to start a task by using default values and without acquiring additional parameters. En el ejemplo siguiente se usa el Task.Run<TResult>(Func<TResult>) método para iniciar una tarea que ejecuta un bucle y, a continuación, muestra el número de iteraciones del bucle:The following example uses the Task.Run<TResult>(Func<TResult>) method to start a task that loops and then displays the number of loop iterations:

using System;
using System.Threading.Tasks;

public class Example
{
   public static void Main()
   {
      var t = Task<int>.Run( () => {
                                      // Just loop.
                                      int max = 1000000;
                                      int ctr = 0;
                                      for (ctr = 0; ctr <= max; ctr++) {
                                         if (ctr == max / 2 && DateTime.Now.Hour <= 12) {
                                            ctr++;
                                            break;
                                         }
                                      }
                                      return ctr;
                                    } );
      Console.WriteLine("Finished {0:N0} iterations.", t.Result);
   }
}
// The example displays output like the following:
//        Finished 1,000,001 loop iterations.
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim t As Task(Of Integer) = Task.Run(Function()
                                  Dim max As Integer = 1000000
                                  Dim ctr As Integer
                                  For ctr = 0 to max
                                     If ctr = max \ 2 And Date.Now.Hour <= 12 Then
                                        ctr += 1
                                        Exit For
                                     End If
                                  Next
                                  Return ctr
                               End Function)
      Console.WriteLine("Finished {0:N0} iterations.", t.Result)
   End Sub
End Module
' The example displays the following output:
'       Finished 1,000,001 loop iterations

Una alternativa y la manera más común para iniciar una tarea el .NET Framework 4.NET Framework 4, consiste en llamar a estático TaskFactory.StartNew o TaskFactory<TResult>.StartNew método.An alternative, and the most common way to start a task in the .NET Framework 4.NET Framework 4, is to call the static TaskFactory.StartNew or TaskFactory<TResult>.StartNew method. El Task.Factory propiedad devuelve un TaskFactory objeto y el Task<TResult>.Factory propiedad devuelve un TaskFactory<TResult> objeto.The Task.Factory property returns a TaskFactory object, and the Task<TResult>.Factory property returns a TaskFactory<TResult> object. Las sobrecargas de sus StartNew método le permite pasar argumentos, definir las opciones de creación de tareas y especificar un programador de tareas.Overloads of their StartNew method let you pass arguments, define task creation options, and specify a task scheduler. En el ejemplo siguiente se usa el TaskFactory<TResult>.StartNew(Func<TResult>) método para iniciar una tarea.The following example uses the TaskFactory<TResult>.StartNew(Func<TResult>) method to start a task. Es funcionalmente equivalente al código en el ejemplo anterior.It is functionally equivalent to the code in the previous example.

using System;
using System.Threading.Tasks;

public class Example
{
   public static void Main()
   {
      var t = Task<int>.Factory.StartNew( () => {
                                      // Just loop.
                                      int max = 1000000;
                                      int ctr = 0;
                                      for (ctr = 0; ctr <= max; ctr++) {
                                         if (ctr == max / 2 && DateTime.Now.Hour <= 12) {
                                            ctr++;
                                            break;
                                         }
                                      }
                                      return ctr;
                               } );
      Console.WriteLine("Finished {0:N0} iterations.", t.Result);
   }
}
// The example displays the following output:
//        Finished 1000001 loop iterations
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim t = Task(Of Integer).Factory.StartNew(Function()
                                  Dim max As Integer = 1000000
                                  Dim ctr As Integer
                                  For ctr = 0 to max
                                     If ctr = max \ 2 And Date.Now.Hour <= 12 Then
                                       ctr += 1
                                       Exit For
                                     End If
                                  Next
                                  Return ctr
                               End Function)
      Console.WriteLine("Finished {0:N0} iterations.", t.Result)
   End Sub
End Module
' The example displays output like the following:
'       Finished 1,000,001 iterations

Para obtener ejemplos más completos, vea basado en tareas de programación asincrónica.For more complete examples, see Task-based Asynchronous Programming.

La Task<TResult> clase también proporciona constructores que inicializan la tarea pero que no programar su ejecución.The Task<TResult> class also provides constructors that initialize the task but that do not schedule it for execution. Por motivos de rendimiento, la Task.Run y Task.Factory.StartNew métodos son los mecanismos preferidos para crear y programar tareas de cálculo, pero para escenarios donde la creación de tareas y la programación deben estar separados, se pueden usar los constructores y el la tarea Start método puede utilizarse para programar la tarea para su ejecución en un momento posterior.For performance reasons, the Task.Run and Task.Factory.StartNew methods are the preferred mechanisms for creating and scheduling computational tasks, but for scenarios where task creation and scheduling must be separated, the constructors may be used, and the task's Start method may then be used to schedule the task for execution at a later time.

Empezando por las aplicaciones de escritorio que tienen como destino el .NET Framework 4.6.NET Framework 4.6, la referencia cultural del subproceso que crea e invoca una tarea se convierte en parte del contexto del subproceso.Starting with desktop apps that target the .NET Framework 4.6.NET Framework 4.6, the culture of the thread that creates and invokes a task becomes part of the thread's context. Es decir, independientemente de la referencia cultural del subproceso en el que se ejecuta la tarea, la referencia cultural actual de la tarea es la referencia cultural del subproceso que realiza la llamada.That is, regardless of the current culture of the thread on which the task executes, the current culture of the task is the culture of the calling thread. Para las aplicaciones destinadas a versiones de .NET Framework anteriores a la .NET Framework 4.6.NET Framework 4.6, la referencia cultural de la tarea es la referencia cultural del subproceso en el que se ejecuta la tarea.For apps that target versions of the .NET Framework prior to the .NET Framework 4.6.NET Framework 4.6, the culture of the task is the culture of the thread on which the task executes. Para obtener más información, consulte la sección "Referencia cultural y operaciones asincrónicas basadas en tareas" en el CultureInfo tema.For more information, see the "Culture and task-based asynchronous operations" section in the CultureInfo topic. Tenga en cuenta que las aplicaciones de Store siguen el tiempo de ejecución de Windows en establecer y obtener la referencia cultural predeterminada.Note that Store apps follow the Windows Runtime in setting and getting the default culture.

Para las operaciones que no devuelven un valor, se usa el Task clase.For operations that do not return a value, you use the Task class. A partir de C# 7.0, para una tarea más ligera que es un tipo de valor en lugar de un tipo de referencia, utilice el System.Threading.Tasks.ValueTask<TResult> estructura.Starting with C# 7.0, for a more lightweight task that is a value type rather than a reference type, use the System.Threading.Tasks.ValueTask<TResult> structure.

Constructores

Task<TResult>(Func<Object,TResult>, Object) Task<TResult>(Func<Object,TResult>, Object) Task<TResult>(Func<Object,TResult>, Object) Task<TResult>(Func<Object,TResult>, Object)

Inicializa una nueva instancia de Task<TResult> con la función y el estado especificados.Initializes a new Task<TResult> with the specified function and state.

Task<TResult>(Func<Object,TResult>, Object, CancellationToken) Task<TResult>(Func<Object,TResult>, Object, CancellationToken) Task<TResult>(Func<Object,TResult>, Object, CancellationToken) Task<TResult>(Func<Object,TResult>, Object, CancellationToken)

Inicializa un nuevo objeto Task<TResult> con la acción, el estado y las opciones especificados.Initializes a new Task<TResult> with the specified action, state, and options.

Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions)

Inicializa un nuevo objeto Task<TResult> con la acción, el estado y las opciones especificados.Initializes a new Task<TResult> with the specified action, state, and options.

Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions)

Inicializa un nuevo objeto Task<TResult> con la acción, el estado y las opciones especificados.Initializes a new Task<TResult> with the specified action, state, and options.

Task<TResult>(Func<TResult>) Task<TResult>(Func<TResult>) Task<TResult>(Func<TResult>) Task<TResult>(Func<TResult>)

Inicializa una nueva Task<TResult> con la función especificada.Initializes a new Task<TResult> with the specified function.

Task<TResult>(Func<TResult>, CancellationToken) Task<TResult>(Func<TResult>, CancellationToken) Task<TResult>(Func<TResult>, CancellationToken) Task<TResult>(Func<TResult>, CancellationToken)

Inicializa una nueva Task<TResult> con la función especificada.Initializes a new Task<TResult> with the specified function.

Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions) Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions) Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions) Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions)

Inicializa una nueva Task<TResult> con la función y las opciones de creación especificadas.Initializes a new Task<TResult> with the specified function and creation options.

Task<TResult>(Func<TResult>, TaskCreationOptions) Task<TResult>(Func<TResult>, TaskCreationOptions) Task<TResult>(Func<TResult>, TaskCreationOptions) Task<TResult>(Func<TResult>, TaskCreationOptions)

Inicializa una nueva Task<TResult> con la función y las opciones de creación especificadas.Initializes a new Task<TResult> with the specified function and creation options.

Propiedades

AsyncState AsyncState AsyncState AsyncState

Obtiene el objeto de estado que se proporcionó al crearse el objeto Task, o null si no se proporcionó ningún objeto de estado.Gets the state object supplied when the Task was created, or null if none was supplied.

(Inherited from Task)
CreationOptions CreationOptions CreationOptions CreationOptions

Obtiene el objeto TaskCreationOptions usado para crear esta tarea.Gets the TaskCreationOptions used to create this task.

(Inherited from Task)
Exception Exception Exception Exception

Obtiene la excepción AggregateException que causó la finalización prematura del objeto Task.Gets the AggregateException that caused the Task to end prematurely. Si Task se completó correctamente o no ha iniciado ninguna excepción, el valor devuelto será null.If the Task completed successfully or has not yet thrown any exceptions, this will return null.

(Inherited from Task)
Factory Factory Factory Factory

Proporciona acceso a métodos Factory Method para crear y configurar instancias de Task<TResult>.Provides access to factory methods for creating and configuring Task<TResult> instances.

IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle

Obtiene un identificador WaitHandle que se puede usar para esperar a que se complete la tarea.Gets a WaitHandle that can be used to wait for the task to complete.

(Inherited from Task)
IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously

Obtiene un valor que indica si la operación se ha completado sincrónicamente.Gets an indication of whether the operation completed synchronously.

(Inherited from Task)
Id Id Id Id

Obtiene un identificador para esta instancia de Task.Gets an ID for this Task instance.

(Inherited from Task)
IsCanceled IsCanceled IsCanceled IsCanceled

Obtiene un valor que indica si esta instancia de Task ha completado su ejecución debido a una cancelación.Gets whether this Task instance has completed execution due to being canceled.

(Inherited from Task)
IsCompleted IsCompleted IsCompleted IsCompleted

Obtiene un valor que indica si la tarea se ha completado.Gets a value that indicates whether the task has completed.

(Inherited from Task)
IsCompletedSuccessfully IsCompletedSuccessfully IsCompletedSuccessfully IsCompletedSuccessfully Inherited from Task
IsFaulted IsFaulted IsFaulted IsFaulted

Obtiene un valor que indica si el objeto Task se ha completado debido a una excepción no controlada.Gets whether the Task completed due to an unhandled exception.

(Inherited from Task)
Result Result Result Result

Obtiene el valor de resultado de este objeto Task<TResult>.Gets the result value of this Task<TResult>.

Status Status Status Status

Obtiene el objeto TaskStatus de esta tarea.Gets the TaskStatus of this task.

(Inherited from Task)

Métodos

ConfigureAwait(Boolean) ConfigureAwait(Boolean) ConfigureAwait(Boolean) ConfigureAwait(Boolean)

Configura un awaiter utilizado para esperar a este objeto Task<TResult>.Configures an awaiter used to await this Task<TResult>.

ContinueWith(Action<Task,Object>, Object) ContinueWith(Action<Task,Object>, Object) ContinueWith(Action<Task,Object>, Object) ContinueWith(Action<Task,Object>, Object)

Crea una continuación que recibe información de estado proporcionada por el autor de la llamada y se ejecuta cuando el elemento Task de destino se completa.Creates a continuation that receives caller-supplied state information and executes when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, CancellationToken) ContinueWith(Action<Task,Object>, Object, CancellationToken) ContinueWith(Action<Task,Object>, Object, CancellationToken) ContinueWith(Action<Task,Object>, Object, CancellationToken)

Crea una continuación que recibe información de estado proporcionada por el autor de la llamada y un token de cancelación y que se ejecuta de forma asincrónica cuando el elemento Task de destino se completa.Creates a continuation that receives caller-supplied state information and a cancellation token and that executes asynchronously when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que recibe información de estado proporcionada por el autor de la llamada y un token de cancelación y que se ejecuta cuando el elemento Task de destino se completa.Creates a continuation that receives caller-supplied state information and a cancellation token and that executes when the target Task completes. La continuación se ejecuta según un conjunto de condiciones especificadas y usa un programador especificado.The continuation executes based on a set of specified conditions and uses a specified scheduler.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions)

Crea una continuación que recibe información de estado proporcionada por el autor de la llamada y se ejecuta cuando el elemento Task de destino se completa.Creates a continuation that receives caller-supplied state information and executes when the target Task completes. La continuación se ejecuta según un conjunto de condiciones especificadas.The continuation executes based on a set of specified conditions.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, TaskScheduler) ContinueWith(Action<Task,Object>, Object, TaskScheduler) ContinueWith(Action<Task,Object>, Object, TaskScheduler) ContinueWith(Action<Task,Object>, Object, TaskScheduler)

Crea una continuación que recibe información de estado proporcionada por el autor de la llamada y se ejecuta de forma asincrónica cuando el elemento Task de destino se completa.Creates a continuation that receives caller-supplied state information and executes asynchronously when the target Task completes. La continuación usa un programador especificado.The continuation uses a specified scheduler.

(Inherited from Task)
ContinueWith(Action<Task<TResult>,Object>, Object) ContinueWith(Action<Task<TResult>,Object>, Object) ContinueWith(Action<Task<TResult>,Object>, Object) ContinueWith(Action<Task<TResult>,Object>, Object)

Crea una continuación a la que se pasa información de estado y que se ejecuta cuando el objeto Task<TResult> de destino se completa.Creates a continuation that is passed state information and that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>>) ContinueWith(Action<Task<TResult>>) ContinueWith(Action<Task<TResult>>) ContinueWith(Action<Task<TResult>>)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa la tarea de destino.Creates a continuation that executes asynchronously when the target task completes.

ContinueWith(Action<Task<TResult>>, CancellationToken) ContinueWith(Action<Task<TResult>>, CancellationToken) ContinueWith(Action<Task<TResult>>, CancellationToken) ContinueWith(Action<Task<TResult>>, CancellationToken)

Crea una continuación que se puede cancelar y se ejecuta de forma asincrónica al completarse el parámetro Task<TResult> de destino.Creates a cancelable continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que se ejecuta según la condición especificada en continuationOptions.Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) ContinueWith(Action<Task<TResult>>, TaskContinuationOptions)

Crea una continuación que se ejecuta según la condición especificada en continuationOptions.Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith(Action<Task<TResult>>, TaskScheduler) ContinueWith(Action<Task<TResult>>, TaskScheduler) ContinueWith(Action<Task<TResult>>, TaskScheduler) ContinueWith(Action<Task<TResult>>, TaskScheduler)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith(Action<Task>) ContinueWith(Action<Task>) ContinueWith(Action<Task>) ContinueWith(Action<Task>)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa el objeto Task de destino.Creates a continuation that executes asynchronously when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task>, CancellationToken) ContinueWith(Action<Task>, CancellationToken) ContinueWith(Action<Task>, CancellationToken) ContinueWith(Action<Task>, CancellationToken)

Crea una continuación que recibe un token de cancelación y se ejecuta de forma asincrónica cuando el elemento Task de destino se completa.Creates a continuation that receives a cancellation token and executes asynchronously when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que se ejecuta cuando se completa la tarea de destino según el elemento TaskContinuationOptions especificado.Creates a continuation that executes when the target task competes according to the specified TaskContinuationOptions. La continuación recibe un token de cancelación y usa un programador especificado.The continuation receives a cancellation token and uses a specified scheduler.

(Inherited from Task)
ContinueWith(Action<Task>, TaskContinuationOptions) ContinueWith(Action<Task>, TaskContinuationOptions) ContinueWith(Action<Task>, TaskContinuationOptions) ContinueWith(Action<Task>, TaskContinuationOptions)

Crea una continuación que se ejecuta cuando se completa la tarea de destino según el elemento TaskContinuationOptions especificado.Creates a continuation that executes when the target task completes according to the specified TaskContinuationOptions.

(Inherited from Task)
ContinueWith(Action<Task>, TaskScheduler) ContinueWith(Action<Task>, TaskScheduler) ContinueWith(Action<Task>, TaskScheduler) ContinueWith(Action<Task>, TaskScheduler)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa el objeto Task de destino.Creates a continuation that executes asynchronously when the target Task completes. La continuación usa un programador especificado.The continuation uses a specified scheduler.

(Inherited from Task)
ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler)

Crea una continuación que se ejecuta cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que se ejecuta según la condición especificada en continuationOptions.Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions)

Crea una continuación que se ejecuta según la condición especificada en continuationOptions.Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa el objeto Task<TResult> de destino.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith<TResult>(Func<Task,Object,TResult>, Object) ContinueWith<TResult>(Func<Task,Object,TResult>, Object) ContinueWith<TResult>(Func<Task,Object,TResult>, Object) ContinueWith<TResult>(Func<Task,Object,TResult>, Object)

Crea una continuación que recibe información de estado proporcionada por el autor de la llamada y se ejecuta de forma asincrónica cuando el elemento Task de destino se completa y devuelve un valor.Creates a continuation that receives caller-supplied state information and executes asynchronously when the target Task completes and returns a value.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken)

Crea una continuación que se ejecuta de forma asincrónica cuando el elemento Task de destino se completa y devuelve un valor.Creates a continuation that executes asynchronously when the target Task completes and returns a value. La continuación recibe información de estado proporcionada por el autor de la llamada y un token de cancelación.The continuation receives caller-supplied state information and a cancellation token.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que se ejecuta según las opciones de continuación de la tarea especificadas cuando el elemento Task de destino se completa y devuelve un valor.Creates a continuation that executes based on the specified task continuation options when the target Task completes and returns a value. La continuación recibe información de estado proporcionada por el autor de la llamada y un token de cancelación y usa el programador especificado.The continuation receives caller-supplied state information and a cancellation token and uses the specified scheduler.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions)

Crea una continuación que se ejecuta según las opciones de continuación de la tarea especificadas cuando el elemento Task de destino se completa.Creates a continuation that executes based on the specified task continuation options when the target Task completes. La continuación recibe información de estado proporcionada por el autor de la llamada.The continuation receives caller-supplied state information.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler)

Crea una continuación que se ejecuta de manera asincrónica cuando se completa el objeto Task de destino.Creates a continuation that executes asynchronously when the target Task completes. La continuación recibe información de estado proporcionada por el autor de la llamada y usa a un programador especificado.The continuation receives caller-supplied state information and uses a specified scheduler.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>) ContinueWith<TResult>(Func<Task,TResult>) ContinueWith<TResult>(Func<Task,TResult>) ContinueWith<TResult>(Func<Task,TResult>)

Crea una continuación que se ejecuta de forma asincrónica cuando el elemento Task<TResult> de destino se completa y devuelve un valor.Creates a continuation that executes asynchronously when the target Task<TResult> completes and returns a value.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, CancellationToken) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken)

Crea una continuación que se ejecuta de forma asincrónica cuando el elemento Task de destino se completa y devuelve un valor.Creates a continuation that executes asynchronously when the target Task completes and returns a value. La continuación recibe un token de cancelación.The continuation receives a cancellation token.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Crea una continuación que se ejecuta según las opciones de continuación especificadas y devuelve un valor.Creates a continuation that executes according to the specified continuation options and returns a value. Se pasa un token de cancelación a la continuación y usa un programador especificado.The continuation is passed a cancellation token and uses a specified scheduler.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions)

Crea una continuación que se ejecuta según las opciones de continuación especificadas y devuelve un valor.Creates a continuation that executes according to the specified continuation options and returns a value.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler)

Crea una continuación que se ejecuta de forma asincrónica cuando el elemento Task de destino se completa y devuelve un valor.Creates a continuation that executes asynchronously when the target Task completes and returns a value. La continuación usa un programador especificado.The continuation uses a specified scheduler.

(Inherited from Task)
Dispose() Dispose() Dispose() Dispose()

Libera todos los recursos usados por la instancia actual de la clase Task.Releases all resources used by the current instance of the Task class.

(Inherited from Task)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Desecha el objeto Task y libera todos sus recursos no administrados.Disposes the Task, releasing all of its unmanaged resources.

(Inherited from Task)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAwaiter() GetAwaiter() GetAwaiter() GetAwaiter()

Obtiene un awaiter utilizado para esperar este objeto Task<TResult>.Gets an awaiter used to await this Task<TResult>.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
RunSynchronously() RunSynchronously() RunSynchronously() RunSynchronously()

Ejecuta sincrónicamente el objeto Task en el objeto TaskScheduler actual.Runs the Task synchronously on the current TaskScheduler.

(Inherited from Task)
RunSynchronously(TaskScheduler) RunSynchronously(TaskScheduler) RunSynchronously(TaskScheduler) RunSynchronously(TaskScheduler)

Ejecuta sincrónicamente el objeto Task en el objeto TaskScheduler proporcionado.Runs the Task synchronously on the TaskScheduler provided.

(Inherited from Task)
Start() Start() Start() Start()

Inicia el objeto Task, programando su ejecución en el objeto TaskScheduler actual.Starts the Task, scheduling it for execution to the current TaskScheduler.

(Inherited from Task)
Start(TaskScheduler) Start(TaskScheduler) Start(TaskScheduler) Start(TaskScheduler)

Inicia el objeto Task, programando su ejecución en el objeto TaskScheduler especificado.Starts the Task, scheduling it for execution to the specified TaskScheduler.

(Inherited from Task)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)
Wait() Wait() Wait() Wait()

Espera a que se complete la ejecución del objeto Task.Waits for the Task to complete execution.

(Inherited from Task)
Wait(CancellationToken) Wait(CancellationToken) Wait(CancellationToken) Wait(CancellationToken)

Espera a que se complete la ejecución del objeto Task.Waits for the Task to complete execution. La espera finalizará si un token de cancelación se cancela antes de que finalice la tarea.The wait terminates if a cancellation token is canceled before the task completes.

(Inherited from Task)
Wait(Int32) Wait(Int32) Wait(Int32) Wait(Int32)

Espera a que el objeto Task complete la ejecución dentro de un número especificado de milisegundos.Waits for the Task to complete execution within a specified number of milliseconds.

(Inherited from Task)
Wait(Int32, CancellationToken) Wait(Int32, CancellationToken) Wait(Int32, CancellationToken) Wait(Int32, CancellationToken)

Espera a que se complete la ejecución del objeto Task.Waits for the Task to complete execution. La espera finalizará si transcurre un intervalo de tiempo de espera o un token de cancelación se cancela antes de que finalice la tarea.The wait terminates if a timeout interval elapses or a cancellation token is canceled before the task completes.

(Inherited from Task)
Wait(TimeSpan) Wait(TimeSpan) Wait(TimeSpan) Wait(TimeSpan)

Espera a que Task complete la ejecución dentro de un intervalo de tiempo especificado.Waits for the Task to complete execution within a specified time interval.

(Inherited from Task)

Extension Methods

DispatcherOperationWait(Task) DispatcherOperationWait(Task) DispatcherOperationWait(Task) DispatcherOperationWait(Task)

Espera indefinidamente a que se complete la DispatcherOperation subyacente.Waits indefinitely for the underlying DispatcherOperation to complete.

DispatcherOperationWait(Task, TimeSpan) DispatcherOperationWait(Task, TimeSpan) DispatcherOperationWait(Task, TimeSpan) DispatcherOperationWait(Task, TimeSpan)

Espera la cantidad de tiempo especificada para que se complete el DispatcherOperation subyacente.Waits for the specified amount of time for the underlying DispatcherOperation to complete.

IsDispatcherOperationTask(Task) IsDispatcherOperationTask(Task) IsDispatcherOperationTask(Task) IsDispatcherOperationTask(Task)

Devuelve un valor que indica si este Task está asociado con un DispatcherOperation.Returns a value that indicates whether this Task is associated with a DispatcherOperation.

AsAsyncAction(Task) AsAsyncAction(Task) AsAsyncAction(Task) AsAsyncAction(Task)

Devuelve una acción asincrónica de Windows Runtime que representa una tarea iniciada.Returns a Windows Runtime asynchronous action that represents a started task.

AsAsyncOperation<TResult>(Task<TResult>) AsAsyncOperation<TResult>(Task<TResult>) AsAsyncOperation<TResult>(Task<TResult>) AsAsyncOperation<TResult>(Task<TResult>)

Devuelve una operación asincrónica de Windows Runtime que representa la tarea iniciada que devuelve un resultado.Returns a Windows Runtime asynchronous operation that represents a started task that returns a result.

Se aplica a

Seguridad para subprocesos

Todos los miembros de Task<TResult>, excepto para Dispose(), son seguros para subprocesos y se pueden usar desde varios subprocesos simultáneamente.All members of Task<TResult>, except for Dispose(), are thread-safe and may be used from multiple threads concurrently.

Consulte también: