Does switching layouts stop the chart's code execution?

When switching from one Layout to another, does the code that was running in the charts complete its execution, or does that code get interrupted before finishing? The reason I ask is that I have some code in a critical section in a chart, and the semaphore was left hanging after switching to a different Layout.

Here are the few actions that will trigger execution of AFL code in an indicator.

  1. Click on the chart
  2. Changing tab(From Sheet1 to Sheet2 where AFL codes in Sheet2 will be executed)
  3. Changing ticker symbol(mouse click or keyboard)

Caution: OLE ActiveDocument.Name will cause AFL code infinite loop. Such statement should be inside a function only trigger by mouse click or keyboard.

You need to be very cautious about locking your critical sections for extended periods of time.
When switching to a different tab or layout AmiBroker must end current execution of the formula to allow unloading formula from tab that is being closed and load a new formula from tab that is being opened. It first asks nicely formula to end at next statement, if the formula is not responding to such request quickly (waiting for example for non-responding OLE server or Internet call) for over 10 seconds it will terminate it forcefully.

Great, thank you. I'll reevaluate how my code is structured so I don't do so much in a critical section (aggregating data for other charts to lookup, so they don't each individually do redundant calcs).