I have updated my demonstration indicator to use a Print statement rather than throwing an exception, because it now seems that throwing an exception during the StateChange to State.Terminated can hang the chart indefinitely.
Here's the demonstration code:
public class TestPrematureTermination : Indicator
{
private bool IsUpdating = false;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Test premature termination issue";
Name = "TestPrematureTermination";
}
else if (State == State.Terminated)
{
if (IsUpdating) Print("Broken");
}
}
protected override void OnBarUpdate()
{
IsUpdating = true;
System.Threading.Thread.Sleep(1);
IsUpdating = false;
}
}
If you simply place this on a chart - for instance, 30 days of 1 minute bars of ES - and hit F5 a few times, you will see the message Broken in the output window, indicating that the unmanaged resources are being destroyed during OnBarUpdate's execution.
Because the stated intention is for us to clean up unmanaged resources during OnStateChange to State.Terminated, this results in exceptions during the execution of OnBarUpdate which relies on those same resources. Shouldn't NT8 wait for OnBarUpdate to exit before changing the state to State.Terminated?
The alternative seems to be that we introduce our own object locking, but this has its own issues.
Please confirm that this is what you expect us to do, in order to avoid exceptions happening that can lock the chart.
Comment