Skip to content
CShift0.32

Thread

Struct · built-in type

struct Thread

The handle of a running thread void function: start Work(10) runs it on its own OS thread and returns a Thread right away. A function with a result gives a Thread<T> instead.

thread void Work(int n) { ... }
Thread t = start Work(10);
t.Join();
Name Description
Cancelled Inside a thread function: whether its thread was asked to stop (Thread.Cancel).
static bool Cancelled

Inside a thread function: whether its thread was asked to stop (Thread.Cancel). The function decides itself when to look and how to stop.

Name Description
Sleep Pauses the calling thread for milliseconds (Thread.Sleep(100): a tenth of a second).
static void Sleep(int milliseconds)

Pauses the calling thread for milliseconds (Thread.Sleep(100): a tenth of a second).

Name Description
Join Waits until the thread has finished.
Cancel Requests cancellation and does not wait: the thread notices it by reading Thread.Cancelled.
CancelAndWait Requests cancellation and waits until the thread has finished.
IsCompleted Whether the thread has finished: by returning, or after a cancellation request.
IsCancelled Whether Thread.Cancel or Thread.CancelAndWait was called; the thread may still be running.
void Join()

Waits until the thread has finished.

void Cancel()

Requests cancellation and does not wait: the thread notices it by reading Thread.Cancelled.

void CancelAndWait()

Requests cancellation and waits until the thread has finished.

bool IsCompleted()

Whether the thread has finished: by returning, or after a cancellation request.

bool IsCancelled()

Whether Thread.Cancel or Thread.CancelAndWait was called; the thread may still be running.