In light of the information at http://ninjatrader.com/support/helpG...fecycle_of.htm, would the buttons being handled in the former link, not get prematurely nulled/destroyed?
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Confused: object life cycle
Collapse
X
-
Confused: object life cycle
In my continuing education about NT8, I was taking another look at the documentation about ChartControl, and came across the example in https://ninjatrader.com/support/help...collection.htm
In light of the information at http://ninjatrader.com/support/helpG...fecycle_of.htm, would the buttons being handled in the former link, not get prematurely nulled/destroyed?Tags: None
-
Hi koganam,
In the life cycle of the indicator being run and then removed, the termination will only occur twice for that instance. However, NT makes several instances of a script (when opening windows, enabling, removing, and other actions) and you will see the terminated state be hit when an indicator is running, but it will be for a different instance of that script.
The running instance would be step 3 (the whole run through) in the flow chart of the life cycle documentation. The other steps are different instances of the script.
In practice, are you finding that buttons added to the UserControlCollection (or added to the WPF elements of the chart) or handlers are being removed prematurely?Chelsea B.NinjaTrader Customer Service
-
Originally posted by NinjaTrader_ChelseaB View PostHi koganam,
In the life cycle of the indicator being run and then removed, the termination will only occur twice for that instance. However, NT makes several instances of a script (when opening windows, enabling, removing, and other actions) and you will see the terminated state be hit when an indicator is running, but it will be for a different instance of that script.
The running instance would be step 3 (the whole run through) in the flow chart of the life cycle documentation. The other steps are different instances of the script.
In practice, are you finding that buttons added to the UserControlCollection (or added to the WPF elements of the chart) or handlers are being removed prematurely?
Last edited by koganam; 03-07-2017, 04:07 PM.
Comment
-
Hi koganam,
This would be good example of this.
The reason we would check that the toolbar was actually added is because, OnTermination() will trigger twice even though the script was not actually run. In steps 1 and 2 of the life cycle, OnTermination will get hit even though the script never ran. Because of this, any objects that would have been created when the script ran never get created. This could lead to errors if there are null objects, or if the script makes changes to the WPF elements of the chart.
I've run into this exact issue when making a ChartSidePanelExample which I have attached. OnTermination gets called even though the script wasn't run and was causing the wrong columns to be removed. To fix it, I ensure the extra panel area was actually added first using a bool. (I don't do this in the same place, but its the same concept)Attached FilesChelsea B.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHi koganam,
This would be good example of this.
The reason we would check that the toolbar was actually added is because, OnTermination() will trigger twice even though the script was not actually run. In steps 1 and 2 of the life cycle, OnTermination will get hit even though the script never ran. Because of this, any objects that would have been created when the script ran never get created. This could lead to errors if there are null objects, or if the script makes changes to the WPF elements of the chart.
I've run into this exact issue when making a ChartSidePanelExample which I have attached. OnTermination gets called even though the script wasn't run and was causing the wrong columns to be removed. To fix it, I ensure the extra panel area was actually added first using a bool. (I don't do this in the same place, but its the same concept)
I am not asking for another explanation of how the object life cycle is handled, or other examples of needing to use an isolating flag: I want to know whether the problem described would not mean that the example on the UserControlCollection page is incorrect, and if not, why not?
Kindly focus on the question. Why is the example code not defective, given how object life cycles are handled means that there will be many calls to State.Terminated that are not called from the object that holds that demonstration code? That is the question: I am not asking for explanations or demonstrations of other code that might or might not have the issue of unexpected cleanup because of the way that State.Terminated is designed or called.Last edited by koganam; 03-08-2017, 07:43 PM.
Comment
-
Hi koganam,
I want to clarify to make sure I'm understanding your inquiry correctly.
You are asking why the example in the UserControlCollection does not use a flag to know when to remove objects from the chart?
The UserControlCollection automatically removes items from the chart, where as the other examples are modifying the WPF elements of the chart directly without the UserControlCollection.
Because this is automatically removing items, all that is needed to be removed is the event handlers which should be removed if the object they are added to is not null.
No flag is necessary because there is no need to know whether the added items should be removed or displayed as this is all automatic.
However, when modifying the chart directly, the script would need to remove any added objects itself, and would need to know whether or not the items it adds should be visible.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by JGriff5646, Today, 10:02 PM
|
0 responses
8 views
0 likes
|
Last Post
by JGriff5646
Today, 10:02 PM
|
||
Started by AdamDJ8, Today, 09:18 PM
|
0 responses
3 views
0 likes
|
Last Post
by AdamDJ8
Today, 09:18 PM
|
||
Started by knowmad, Today, 03:52 AM
|
2 responses
29 views
0 likes
|
Last Post
by knowmad
Today, 09:03 PM
|
||
Started by ETFVoyageur, Today, 07:05 PM
|
0 responses
11 views
0 likes
|
Last Post
by ETFVoyageur
Today, 07:05 PM
|
||
Started by Orion815, 05-02-2024, 08:39 AM
|
2 responses
18 views
0 likes
|
Last Post
by Orion815
Today, 06:24 PM
|
Comment