# Microthread

Kind: Class · Namespace: Sansar.Microthreading · Assembly: Sansar.Script.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Microthreading">Namespace <a href="/scripting/api/sansar.microthreading"><code>Sansar.Microthreading</code></a></span>
<span>Inherits <a href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a></span>
</div>

<span id="T:Sansar.Microthreading.Microthread"></span>

Internal class used to manage scheduling of tasks

```csharp
public class Microthread : IDisposable
```

## Members at a glance

| Kind | Members |
|---|---|
| **Constructors** | [Microthread](#microthread) |
| **Fields** | [ThreadState](#threadstate) |
| **Methods** | [Dispose](#dispose) · [GetCurrentThreadTicks](#getcurrentthreadticks) · [ToString](#tostring) · [Yield](#yield) · [YieldCurrentThread](#yieldcurrentthread) · [YieldIfQuantaExceeded](#yieldifquantaexceeded) |

## Constructors

### Microthread

<div class="api-card">
<span id="M:Sansar.Microthreading.Microthread.#ctor"></span>
<span id="C:Sansar.Microthreading.Microthread()"></span>

```csharp signature
public Microthread()
```

<p class="api-undocumented">No description in the API snapshot.</p>

</div>


## Fields

### ThreadState

<div class="api-card">
<span id="F:Sansar.Microthreading.Microthread.ThreadState"></span>

```csharp signature
protected Microthread.State ThreadState
```

The current state of this thread.

</div>


## Methods

### Dispose

<div class="api-card">
<span id="M:Sansar.Microthreading.Microthread.Dispose"></span>
<span id="M:Sansar.Microthreading.Microthread.Dispose()"></span>

```csharp signature
public virtual void Dispose()
```

Disposes resources used by this microthread.

</div>

### GetCurrentThreadTicks

<div class="api-card">
<span id="M:Sansar.Microthreading.Microthread.GetCurrentThreadTicks"></span>
<span id="M:Sansar.Microthreading.Microthread.GetCurrentThreadTicks()"></span>

```csharp signature
public static long GetCurrentThreadTicks()
```

Returns the time when this thread will yield.

**Returns:** [long](https://learn.microsoft.com/dotnet/api/system.int64) — The timestamp as returned by [`Stopwatch.GetTimestamp`](https://learn.microsoft.com/dotnet/api/system.diagnostics.stopwatch.gettimestamp) when this thread will yield.

</div>

### ToString

<div class="api-card">
<span id="M:Sansar.Microthreading.Microthread.ToString"></span>
<span id="M:Sansar.Microthreading.Microthread.ToString()"></span>

```csharp signature
public override string ToString()
```

<p class="api-undocumented">No description in the API snapshot.</p>

</div>

### Yield

<div class="api-card">
<span id="M:Sansar.Microthreading.Microthread.Yield"></span>
<span id="M:Sansar.Microthreading.Microthread.Yield()"></span>

```csharp signature
public void Yield()
```

Explicitly yield the current thread or coroutine.

</div>

### YieldCurrentThread

<div class="api-card">
<span id="M:Sansar.Microthreading.Microthread.YieldCurrentThread"></span>
<span id="M:Sansar.Microthreading.Microthread.YieldCurrentThread()"></span>

```csharp signature
public static long YieldCurrentThread()
```

Explicitly yield the current thread or coroutine.

**Returns:** [long](https://learn.microsoft.com/dotnet/api/system.int64) — Returns the current thread ticks as returned by [`Microthread.GetCurrentThreadTicks`](/scripting/api/sansar.microthreading/microthread#getcurrentthreadticks).

</div>

### YieldIfQuantaExceeded

<div class="api-card" id="yieldifquantaexceeded-noargs">
<span id="M:Sansar.Microthreading.Microthread.YieldIfQuantaExceeded"></span>
<span id="M:Sansar.Microthreading.Microthread.YieldIfQuantaExceeded()"></span>

```csharp signature
public static void YieldIfQuantaExceeded()
```

Conditionally yields if the thread has exceeded its given runtime.

</div>

<div class="api-card" id="yieldifquantaexceeded-int64">
<span id="M:Sansar.Microthreading.Microthread.YieldIfQuantaExceeded(System.Int64)"></span>

```csharp signature
public static long YieldIfQuantaExceeded(long ticks)
```

Conditionally yields if the thread has exceeded its given runtime.

| Parameter | Type | Description |
|---|---|---|
| `ticks` | [long](https://learn.microsoft.com/dotnet/api/system.int64) |  |

**Returns:** [long](https://learn.microsoft.com/dotnet/api/system.int64)

</div>




<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>