<div class="meta" robots="noindex">

</div>

Class

# Xojo.Threading.Thread

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r2. Please use `Thread</api/language/threading/thread>` as a replacement.

</div>

## Description

Used to run code in the background. Xojo threads are co-operative (not pre-emptive).

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                         | Type                                                  | Read-Only | Shared |
|----------------------------------------------|-------------------------------------------------------|-----------|--------|
| `Priority<xojo.threading.thread.priority>`   | `Integer</api/data_types/integer>`                    |           |        |
| `StackSize<xojo.threading.thread.stacksize>` | `UInteger</api/data_types/additional_types/uinteger>` |           |        |
| `State<xojo.threading.thread.state>`         | `ThreadStates<xojo.threading.thread.threadstates>`    | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                     | Parameters                                                                                                                         | Returns | Shared |
|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
| `Resume<xojo.threading.thread.resume>`   |                                                                                                                                    |         |        |
| `Run<xojo.threading.thread.run_method>`  |                                                                                                                                    |         |        |
| `Sleep<xojo.threading.thread.sleep>`     | milliSeconds As `Integer</api/data_types/integer>`, wakeEarly As `Boolean</api/data_types/boolean>` = `False</api/language/false>` |         |        |
| `Suspend<xojo.threading.thread.suspend>` |                                                                                                                                    |         |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                             | Parameters | Returns |
|----------------------------------|------------|---------|
| `Run<xojo.threading.thread.run>` |            |         |

## Enumerations

<div id="xojo.threading.thread.threadstates">

<div class="rst-class">

forsearch

</div>

</div>

Xojo.Threading.Thread.ThreadStates

### ThreadStates

These are the various states of a thread. (Running, Waiting, Suspended, Sleeping, NotRunning)

| Enum       | Description                      |
|------------|----------------------------------|
| Running    | The thread is currently running. |
| Waiting    | The thread is waiting to run.    |
| Suspended  | The thread is suspended.         |
| Sleeping   | The thread is sleeping.          |
| NotRunning | The thread is not running.       |

## Property descriptions

<div id="xojo.threading.thread.priority">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.Priority

**Priority** As `Integer</api/data_types/integer>`

Indicates the priority of the thread.

The main thread for the app has a priority of 5. You can alter the priority of your own threads to give them more or less time relative to the main thread. The default is also 5.

The higher the priority value, the more time the thread is allocated, in relation to the main thread. For example, if you set the Priority = 10, then your thread will run twice as often as the main thread (since 10 is 5\*2). A Priority value that is too high might prevent other threads from running at all.

Set the thread to a low priority:

``` xojo
Thread1.Priority = Thread.PriorityLow
```

<div id="xojo.threading.thread.stacksize">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.StackSize

**StackSize** As `UInteger</api/data_types/additional_types/uinteger>`

The size of the thread stack, in bytes.

<div id="xojo.threading.thread.state">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.State

**State** As `ThreadStates<xojo.threading.thread.threadstates>`

Indicates the state of the thread using the ThreadStates enumeration.

This property is read-only.

Check the state of a thread:

``` xojo
Var status As Text
Select Case state
Case Thread.Running
  status = "Running"
Case Thread.Waiting
  status = "Waiting"
Case Thread.Sleeping
  status = "Waiting"
Case Thread.Suspended
  status = "Suspended"
Case Thread.NotRunning
  status = "Not running"
End Select
```

## Method descriptions

<div id="xojo.threading.thread.resume">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.Resume

**Resume**

Wakes a thread that is sleeping or suspended so that it may continue running.

``` xojo
LongRunningThread.Resume
```

<div id="xojo.threading.thread.run_method">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.Run

**Run**

Starts the thread and calls its Run event handler.

<div id="xojo.threading.thread.sleep">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.Sleep

**Sleep**(milliSeconds As `Integer</api/data_types/integer>`, wakeEarly As `Boolean</api/data_types/boolean>` = `False</api/language/false>`)

Puts the thread to sleep for the specified amount of milliSeconds, optionally allowing it to be woken early.

If wakeEarly is True, a thread may be woken before milliSeconds is reached if there are no other threads to run.

``` xojo
LongRunningThread.Sleep(300)

LongRunningThread.Sleep(1000, True)
```

<div id="xojo.threading.thread.suspend">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.Suspend

**Suspend**

Puts the thread in a suspended state where it will no longer run. You can allow the thread to continue by calling Resume.

When a thread is suspended, it is not allocated any processing time, regardless of its priority.

``` xojo
LongRunningThread.Suspend

' Other code goes here

LongRunningThread.Resume
```

## Event descriptions

<div id="xojo.threading.thread.run">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Thread.Run

**Run**

Called when the thread is started by calling the Run method. The code you want to run in the thread should be in this event handler or should be called from it.

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `CriticalSection</api/language/threading/criticalsection>`, `Semaphore</api/language/threading/semaphore>` classes
