Is it safe to use OnTimer like this?

Created at 25 Feb 2015, 22:50
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AI

AimHigher

Joined 04.01.2014

Is it safe to use OnTimer like this?
25 Feb 2015, 22:50


protected override void OnStart()
        {

        Timer.Start(TimeSpan.FromMilliseconds(1));
            
        }

protected override void OnTick()
        {
	    Timer.Stop();

	//Do some calculations

            Timer.Start(TimeSpan.FromMilliseconds(1));
        }

protected override void OnTimer()
        {
          OnTick();
        }

protected override void OnStop()
        {
            Timer.Stop();
        }

Would the code above work without risk causing cAlgo to crash?

Timer is from cAlgo.API.

Appreciate any and all input.

Aim


@AimHigher
Replies

Spotware
27 Feb 2015, 14:50

Yes, it is safe. cAlgo invokes OnTimer method in the same thread as OnStart, OnTick and other methods. You can use cAlgo.API.Timer without multi-threading issues.


@Spotware

AimHigher
27 Feb 2015, 23:26

Thank you. The new Timer and RefreshData() have increased the value (to me) of your platform tremendously.

Regards,

Aim


@AimHigher