- OnStateChanged() with State = State.SetDefaults
- [External Code]
- My own indicator base class constructor -- just entering it, no code yet executed
- My indicator's default constructor -- no code run yet, because the initializer call to the base class constructor has not yet returned
- [External Code]
What I do not understand is how OnStateChanged() can be getting called before the constructor has completed. There is no way that should be happening. No object can be assumed ready to be called before its constructor has completed.
I cannot see how this is happening unless it is some sort of multi-threading thing. I certainly was not aware that I had to ensure my indicator instance is thread-safe, and I hope that is not the case.
So ... please ... someone tell me how OnStateChange() is getting called before the constructor completes! That should not be happening!
=====
I got here by:
- Starting Ninatrader 8. It came up in a workspace with one chart that had no indicators. No sign of any problem so far.
- Visual Studio attach to the process. That went cleanly, too.
- Bring up the Indicators dialog on the chart. As I understand it, NT generates an instance of each indicator during that process.
- Hit the only breakpoint I have set -- at the entry to OnStateChange()
- Noted the stack as described above -- constructors had been called, but not yet done anything.
At that point I verified a couple of things
- I keep an internal object instance serial number, set by variable initialization that is done prior to the constructor. It was set to "1", consistent with this being the first instance created.
- I keep an internal state. It is compile-time initialized to "not constructed" and then updated at runtime as appropriate. It was still saying "not constructed", even though I am sitting at a breakpoint is OnStateChange(). That is consistent with what the stack is telling me -- that my constructors had not yet had a chance to construct anything. (The very first thing the constructor does is set that internal state to "being constructed".)
All I can say is that from all I am seeing the situation should not be possible. My internal state is consistent with what the stack is telling me -- that I am in OnStateChanged() before the constructor has run. Not Nice!
FWIW: this is not a one-off freak -- I tried again and the same thing happened.
--EV
Comment