> For the complete documentation index, see [llms.txt](https://monytools.gitbook.io/type/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://monytools.gitbook.io/type/threading.md).

# Threading

### Register

`MTools.Threading.Register(callback, critical, other);`

| Name     | Type       | Description                                                            |
| -------- | ---------- | ---------------------------------------------------------------------- |
| callback | `function` | A function called in another thread.                                   |
| critical | `table`    | Optional. Releases ownership of the specified critical section object. |
| other    | `all`      | It is better to use 1. Other arguments.                                |

**Allows functions to be called in separate threads.**\
\ <mark style="color:green;">**Example usage:**</mark>

```lua
MTools.FileSystem.CreateDir("nl\\Test");

function MonyTools()
    MTools.Network.Download("https://www.meme-arsenal.com/memes/96941a83a50bc9cbb0a4fefc5a581eac.jpg", "nl\\Test\\Meme.png");
end

local Test = MTools.Threading:Register(MonyTools, nil, 1);
-- Allows you to download any files without freezing the game.
```

### Destroy

`Thread:Destroy();`

| Name | Type | Description |
| ---- | ---- | ----------- |
| -    | -    | -           |

**Allows you to kill the flow.**\
\ <mark style="color:green;">**Example usage:**</mark>

```lua
-- You can use the example from Register.
Test:Destroy();
-- In this case "Test" is the name of the variable to which the thread from the example above is assigned.
```
