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!
See more
See less

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 DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Working...
        X