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

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

# Plugin.BeginInvokeOnMainThread

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

## BeginInvokeOnMainThread(Action action)

Invokes asynchronously the specified code on the main Plugin thread.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Plugins cannot run in the CLI: ctrader-cli runs cBots only.
- Cloud: Plugins cannot run in the cloud: it runs cBots only.

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 Plugin thread

### Examples

C#:

```csharp
Task.Run(() =>
{
    var response = Http.Get("https://ctrader.com/");
    BeginInvokeOnMainThread(() => Print("Status code: {0}", response.StatusCode));
});
```

Python:

```python
api.BeginInvokeOnMainThread(lambda: api.Print("Running on the plugin main thread"))
```

