class · System.Threading.Tasks

Task

public class System.Threading.Tasks.Task : System.Any

Work that finishes later: an async function, a delay, several tasks together. In an async function, await waits for one; elsewhere, Wait() runs the scheduler until it is done. A task finishes once: done, or failed (await and Wait() then throw its error).

Kind
class
Namespace
System.Threading.Tasks
Assembly
System.Core
Access
public
Source file
Tasks.ant

Inheritance

Base classes
Any Task
Derived types
CompleteTask Task<T> WhenAllTask

Properties

property IsCompleted: bool
#

read-only

Whether it has finished (done or failed).

property IsFaulted: bool
#

read-only

Whether it failed.

static property CompletedTask: System.Threading.Tasks.Task
#

static read-only

A task done.

Methods

method Complete() -> void
#

Done: what waits for it runs (in its turn).

method Fail(failure: System.Any) -> void
#

Failed with failure: what waits for it runs and finds the error.

method Run() -> void
#

virtual

Something this task waits for is done (an async function goes on from its await). The scheduler calls it.

method Pause(awaited: System.Threading.Tasks.Task) -> bool
#

inherited

An async function at an await: false when awaited is done (it goes on); otherwise this task runs again once it is, and true (the function pauses).

method AddWaiter(task: System.Threading.Tasks.Task) -> void
#

inherited

method AddWaiterLocked(task: System.Threading.Tasks.Task) -> void
#

inherited

method Finish(how: i32, failure: System.Any?) -> void
#

inherited

Finishes it once threads complete tasks: under the scheduler's lock, and every waiting thread is told.

method Wake() -> void
#

inherited

method Wait() -> void
#

Runs the scheduler until this task has finished (on another thread than the scheduler's: waits for it); throws its error if it failed.

method Check() -> void
#

What await does once the task has finished: throws its error if it failed.

static method Delay(milliseconds: i32) -> System.Threading.Tasks.Task
#

static

A task done after milliseconds (measured by the scheduler, which sleeps when nothing else is ready).

static method Yield() -> System.Threading.Tasks.Task
#

static

A task done once the tasks ready now have had their turn: await Task.Yield(); lets them run.

static method Done() -> System.Threading.Tasks.Task
#

static

static method WhenAll(tasks: System.Threading.Tasks.Task[]) -> System.Threading.Tasks.Task
#

static

A task done when every one of tasks has finished (failed if one of them failed: the first error).

static method Run(body: func<> : void) -> System.Threading.Tasks.Task
#

static

Runs body on the thread pool: a task done when it returns (failed if it throws).

static method Run<T>(body: func<> : T) -> System.Threading.Tasks.Task<T>
#

static

Runs body on the thread pool: a task with what it returns.

Private and internal members (4)

field state: i32
#

private

0 running, 1 done, 2 failed.

field error: System.Any?
#

private

private

The tasks waiting for this one: the first in a field (most tasks have one), the others in a list.

private

Inherited members (5)

Source

Task as Larva HIR, decompiled from its Larva HIR.

System.Threading.Tasks.Task.hir
// Work that finishes later: an async function, a delay, several tasks together. In an async function, `await`
// waits for one; elsewhere, `Wait()` runs the scheduler until it is done. A task finishes once: done, or failed
// (`await` and `Wait()` then throw its error).
public class System.Threading.Tasks.Task : System.Any
{
    // 0 running, 1 done, 2 failed.
    field state: i32
    field error: System.Any?
    // The tasks waiting for this one: the first in a field (most tasks have one), the others in a list.
    field waiter: System.Threading.Tasks.Task?
    field waiters: System.List<System.Threading.Tasks.Task>?
    // Done: what waits for it runs (in its turn).
    method Complete() -> void
    // Failed with `failure`: what waits for it runs and finds the error.
    method Fail(failure: System.Any) -> void
    // Something this task waits for is done (an async function goes on from its `await`). The scheduler calls it.
    method Run() -> void
    // An async function at an `await`: false when `awaited` is done (it goes on); otherwise this task runs again
    // once it is, and true (the function pauses).
    method Pause(awaited: System.Threading.Tasks.Task) -> bool
    method AddWaiter(task: System.Threading.Tasks.Task) -> void
    method AddWaiterLocked(task: System.Threading.Tasks.Task) -> void
    // Finishes it once threads complete tasks: under the scheduler's lock, and every waiting thread is told.
    method Finish(how: i32, failure: System.Any?) -> void
    method Wake() -> void
    // Runs the scheduler until this task has finished (on another thread than the scheduler's: waits for it);
    // throws its error if it failed.
    method Wait() -> void
    // What `await` does once the task has finished: throws its error if it failed.
    method Check() -> void
    // A task done after `milliseconds` (measured by the scheduler, which sleeps when nothing else is ready).
    static method Delay(milliseconds: i32) -> System.Threading.Tasks.Task
    // A task done once the tasks ready now have had their turn: `await Task.Yield();` lets them run.
    static method Yield() -> System.Threading.Tasks.Task
    static method Done() -> System.Threading.Tasks.Task
    // A task done when every one of `tasks` has finished (failed if one of them failed: the first error).
    static method WhenAll(tasks: System.Threading.Tasks.Task[]) -> System.Threading.Tasks.Task
    // Runs `body` on the thread pool: a task done when it returns (failed if it throws).
    static method Run(body: func<> : void) -> System.Threading.Tasks.Task
    // Runs `body` on the thread pool: a task with what it returns.
    static method Run<T>(body: func<> : T) -> System.Threading.Tasks.Task<T>
    // Whether it has finished (done or failed).
    property IsCompleted: bool
    // Whether it failed.
    property IsFaulted: bool
    // A task done.
    static property CompletedTask: System.Threading.Tasks.Task
}
Esc