Skip to content

Thread Safety

How a cBot/Indicator Runs?

cTrader runs each indicator/cBot on a separate sub process isolated from cTrader desktop main process, all instances of an indicator/cBot will run on a single separate process.

By running them on their own process cTrader separate them from main cTrader process and it allows cTrader to impose code access restrictions on them.

Another great benefit of using separate processes for indicator/cBot is that their resources aren't shared with cTrader desktop main process, so if something goes wrong on an indicator or cBot it will not have any effect on cTrader desktop main process.

Is Automate API thread safe?

No, it's not, only few methods in Automate API are thread safe which you can call them from any thread, everything else should run via cBot/Indicator main thread.

How to run something in cBot/Indicator main thread?

To run something on main thread of a cBot/Indicator you should use the BeginInvokeOnMainThread method, this method accepts an action delegate and you can call it from any running thread.

Can I use static properties/fields to share data between indicator/cBot instances?

Yes, you can, as each indicator/cBot instances run on a single child process you can use static properties or fields to share data in between same indicator/cBot instances.

Last update: September 26, 2022