Skip to main content

Results for: task


A fourth task executes a lambda expression (an Action delegate) that is defined inline in the call to the task creation method. Each task is instantiated and run in a different way: Task t1 is instantiated by calling a Task class constructor, but is started by calling its Start() method only after task t2 has started.

Remarks. The Task<TResult> class represents a single operation that returns a value and that usually executes asynchronously. Task<TResult> objects are one of the central components of the task-based asynchronous pattern first introduced in the .NET Framework 4. Because the work performed by a Task<TResult> object typically executes asynchronously on a thread pool thread rather than ...

The Result of the returned task will be set to an array containing all of the results of the supplied tasks in the same order as they were provided (e.g. if the input tasks array contained t1, t2, t3, the output task's Result will return an TResult[] where arr[0] == t1.Result, arr[1] == t2.Result, and arr[2] == t3.Result).

WhenAny(IEnumerable<Task>) Creates a task that will complete when any of the supplied tasks have completed. WhenAny(Task[]) Creates a task that will complete when any of the supplied tasks have completed.

Examples. The following example calls the Task(Action) constructor to instantiate a new Task object that displays its task ID and managed thread ID and then executes a loop. It then calls the Start method to execute the task. Since this is a console app, the call to the Wait method is necessary to prevent the app from terminating before the task finishes execution.