• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cleaning up resources in an addon

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

    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?


    #2
    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, 02:08 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      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?

      Comment


        #4
        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.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by SBoroman, Today, 06:13 AM
        0 responses
        2 views
        0 likes
        Last Post SBoroman  
        Started by _Cujo, Today, 05:52 AM
        0 responses
        4 views
        0 likes
        Last Post _Cujo
        by _Cujo
         
        Started by ntbone, Today, 05:31 AM
        0 responses
        5 views
        0 likes
        Last Post ntbone
        by ntbone
         
        Started by Vincere, Today, 03:08 AM
        0 responses
        4 views
        0 likes
        Last Post Vincere
        by Vincere
         
        Started by curious, Today, 02:17 AM
        2 responses
        11 views
        0 likes
        Last Post curious
        by curious
         
        Working...
        X