Thread
Struct · built-in type
struct ThreadThe 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();Static fields
Section titled “Static fields”| Name | Description |
|---|---|
Cancelled |
Inside a thread function: whether its thread was asked to stop (Thread.Cancel). |
Cancelled
Section titled “Cancelled”static bool CancelledInside a thread function: whether its thread was asked to stop (Thread.Cancel). The function decides itself
when to look and how to stop.
Static methods
Section titled “Static methods”| 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).
Methods
Section titled “Methods”| 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.
Cancel
Section titled “Cancel”void Cancel()Requests cancellation and does not wait: the thread notices it by reading Thread.Cancelled.
CancelAndWait
Section titled “CancelAndWait”void CancelAndWait()Requests cancellation and waits until the thread has finished.
IsCompleted
Section titled “IsCompleted”bool IsCompleted()Whether the thread has finished: by returning, or after a cancellation request.
IsCancelled
Section titled “IsCancelled”bool IsCancelled()Whether Thread.Cancel or Thread.CancelAndWait was called; the thread may still be running.