Skip to content

Thread safety

How cTrader runs algos

cTrader runs each indicator or cBot on a separate sub-process isolated from the cTrader Windows main process. This means that all new instances of indicators and cBots run on separate processes.

This approach allows cTrader to impose code access restrictions on separate processes, improving safety and stability.

Furthermore, separate indicator or cBot processes do not share their resources with the main cTrader Windows process. If something goes wrong with an indicator or a cBot, the underlying issue will not have an effect on cTrader itself.

Methods and thread safety

Only a few methods in the API are thread-safe, meaning you can call them from any thread. Everything else should run on the cBot or indicator main thread.

Execute code on the main thread

To run something on the main thread of a cBot or indicator, use the BeginInvokeOnMainThread() method. It accepts an action delegate and you can call it from any running thread.

Share data between instances

As each indicator or cBot instance runs on a single child process, you can use static properties or fields to share data between the different instances of the same cBot or indicator.