---
id: "M:cAlgo.API.Internals.Algo.BeginInvokeOnMainThread(System.Action)"
kind: "method"
type: "T:cAlgo.API.Internals.Algo"
url: "https://help.ctrader.com/ctrader-algo/references/General/Algo/BeginInvokeOnMainThread/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# Algo.BeginInvokeOnMainThread

Member of [Algo](https://help.ctrader.com/ctrader-algo/references/General/Algo/index.md).

## BeginInvokeOnMainThread(Action action)

Invokes asynchronously the specified code on the main cBot or Indicator thread.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
public void BeginInvokeOnMainThread(Action action)
```

Python:

```python
api.BeginInvokeOnMainThread(action: Action) -> None
```

### Parameters

- `action` (`Action`, Python `Action`): The code to invoke on the main cBot/Indicator thread

### Examples

C#:

```csharp
Task.Run(() =>
{
    var result = Math.Sqrt(2);
    BeginInvokeOnMainThread(() => Print("Calculated on a background thread: {0}", result));
});
```

Python:

```python
api.BeginInvokeOnMainThread(lambda: api.Print(f"Running on the main thread at {api.Server.Time}"))
```

