Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cleaning up resources in an addon

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_ChelseaB
    replied
    Hello NinjaCustomer,

    The NinjaScript Editor window itself has special code to monitor for file changes on a timer and trigger a compile when it is open if changes are detected.

    If all NinjaScript Editors are closed, the compile will not be triggered.

    The states of all addon classes will be terminated and OnWindowDestroyed() / OnWindowCreated() will be triggered for all open windows. (This is so you can add items to the Control Center New menu if you want after a compile)

    Let me know if you want a video demonstrating this.

    Leave a comment:


  • NinjaCustomer
    replied
    what triggers the automatic compile then? definitely ninjatrader will compile - I can see it in the ninjascript editor animation. What I do is I edit a copy of my .cs files outside of the documents folder then i copy them into custom when I want to "deploy" them to ninjatrader. But doing so will trigger the automatic compile, the animation starts and i hear a compile finished sound.

    I do have a print message that is displayed when Terminated is called in onstatechange, however this mesage only gets printed upon initial loading of ninjatrader , not when an automatic recompile is triggered (however I can see from other print messages that the addon did get reloaded).. so it doesn't seem I can rely on terminated. Do you think onwindowdestroyed will probably get called for sure before the addon is reloaded?

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello NinjaCustomer,

    Just to clarify, the Addon class itself will have a single instance and will be terminated and recreated when compiling.
    The the OnWindowCreated() / OnWindowDestroyed() also will trigger for all windows when a compile occurs.

    However, any window that is created from the Addon (such as when clicking the Addon name in the Control Center > New menu) is a separate class from the addon will not be terminated.

    NinjaTrader does automatically trigger a compile anytime the NinjaScript Editor is open and a change is detected in a .cs file.
    There will not be an automatic compile if the NinjaScript Editor is closed.

    If you have a window that is opening, I recommend cleaning up Window class resources when the Closing event for the window is triggered.
    http://ninjatrader.com/support/forum...059#post477059

    If you do not have a window opening, cleaning up Addon class resources in OnStateChange when State is State.Terminated is fine to do.

    Starting NinjaTrader and compiling are the two triggers that will cause an addon instance to be created.

    NinjaTrader will not automatically create an
    Last edited by NinjaTrader_ChelseaB; 05-21-2019, 01:08 PM.

    Leave a comment:


  • NinjaCustomer
    started a topic Cleaning up resources in an addon

    Cleaning up resources in an addon

    The problem I am having is occurring because the addon is being terminated and restarted.

    I believe this is occurring because the NinjaScript editor is opening and this forces a recompile when it detects changes to the cs files in the custom folder.

    please correct me if I'm wrong and the ninjascript editor does not have to be open for this, and it is just based on detecting a file system change even if the editor is closed.

    so my questions are:

    1) how can I call some cleanup code when the addon is about to terminated? would onstatechange terminated work?

    2) are there any other cirumstances where an addon might be restarted?

Latest Posts

Collapse

Topics Statistics Last Post
Started by ganeshkhere, Yesterday, 08:46 AM
3 responses
17 views
0 likes
Last Post NinjaTrader_Jason  
Started by REI140205, Yesterday, 06:17 PM
3 responses
19 views
0 likes
Last Post NinjaTrader_Jason  
Started by prodigaltrader, Today, 12:18 AM
0 responses
11 views
0 likes
Last Post prodigaltrader  
Started by owenwong, Yesterday, 06:34 PM
2 responses
30 views
0 likes
Last Post owenwong  
Started by Gathem, Yesterday, 06:06 PM
1 response
24 views
0 likes
Last Post Gathem
by Gathem
 
Working...
X