Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cleaning up resources (DLLs) in NT8

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

    Cleaning up resources (DLLs) in NT8

    I just came across this in the best practices section of NT8:

    "Always free up resources such as external windows DLL's or license management related resources. Resources should be freed within the OnStateChange() method in State.Terminate. NinjaTrader calls this method as an script is no longer used."

    FYI - a typo in there...

    Anyway, could you guys elaborate a little? I use DLLs quite extensively for logging and messaging. Would love to see an example that shows what you are referring to.

    Thanks in advance.

    #2
    Hello molecool,

    Thank you for your post.

    We will update this information and provide an example.

    Comment


      #3
      Hello molecool,

      Thank you for your patience.

      There would not be a broad enough example here. Do you have a case of what you are looking for here?

      I look forward to your response.

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello molecool,

        Thank you for your patience.

        There would not be a broad enough example here. Do you have a case of what you are looking for here?

        I look forward to your response.
        Thanks Patrick - I have written a few DLLs which have worked fine over the years. Used one of them in NT8 - not even recompiled to 4.5 and it seems to work. But clearly it hasn't been stress tested and with the new multi threading there may be issues I'm not aware of. So a best practices page would be great.

        Personally I mostly use DLLs to plug in outside functionality. I wrote a Jabber module for instance, and one for Twitter messages. Also added Google docs to my strategy - more complex but it works fine in NT7. Mostly static methods and I am using threading to launch separate threads. Especially Google docs is slow as a.... and it would hang up NinjaTrader for a minute if I wouldn't use a separate thread.

        Again, no issues in NT7 - still need to test that one in NT8.

        Comment


          #5
          Hello molecool,

          Thank you for your follow up.

          We are working on improving the documentation. Feel free to pass along any suggestions you may have.

          Comment


            #6
            Originally posted by NinjaTrader_PatrickH View Post
            Hello molecool,

            Thank you for your follow up.

            We are working on improving the documentation. Feel free to pass along any suggestions you may have.
            Just to circle back to what launched this thread:

            "Always free up resources such as external windows DLL's or license management related resources. Resources should be freed within the OnStateChange() method in State.Terminate. NinjaTrader calls this method as an script is no longer used."

            All I would like to see is an example of that practice - I suspect there are more optimized ways to freeing up resources but I'm not clear on exactly what you guys are proposing.

            Comment


              #7
              Hello,

              There is no specific example of this other than just showing the OnTermination state and explaining what it is for. What you put in this method would solely depend on what you need to execute when the script terminates.

              External DLL's are also outside of the scope of what we support, this note has been placed in the documentation which is only supported practices. This is mainly just a tip for third party developers and is really too broad for a specific example that would apply to most users.

              NinjaTrader in general does not require this method for a majority of scripts, this is put in specifically as a signal that the script is being terminated so if you had knowingly used any resources that need disposed, you could do that here so they are not lingering on after the script ends.

              An example of this method could be your google docs dll, if this needed to have a Disconnect method called to disconnect from the server, you would call it in OnTermination to ensure you get disconnected when the script ends.

              There are very few cases in which this would be used. If your external dll contains nothing that needs disposed or removed, you would not need to use this method at all.

              If you can provide a specific example of an item you use that requires a termination event or needs disposed or a handler removed, I could provide a more helpful example because there is a specific scenario in that case, otherwise I can really only provide information on what this method is for because it highly depends what you are using in the script.

              Please let me know if I may be of additional assistance.
              Last edited by NinjaTrader_Jesse; 06-11-2015, 02:35 PM.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Jesse View Post
                Hello,

                There is no specific example of this other than just showing the OnTermination state and explaining what it is for. What you put in this method would solely depend on what you need to execute when the script terminates.

                External DLL's are also outside of the scope of what we support, this note has been placed in the documentation which is only supported practices. This is mainly just a tip for third party developers and is really too broad for a specific example that would apply to most users.

                NinjaTrader in general does not require this method for a majority of scripts, this is put in specifically as a signal that the script is being terminated so if you had knowingly used any resources that need disposed, you could do that here so they are not lingering on after the script ends.

                An example of this method could be your google docs dll, if this needed to have a Disconnect method called to disconnect from the server, you would call it in OnTermination to ensure you get disconnected when the script ends.

                There are very few cases in which this would be used. If your external dll contains nothing that needs disposed or removed, you would not need to use this method at all.

                If you can provide a specific example of an item you use that requires a termination event or needs disposed or a handler removed, I could provide a more helpful example because there is a specific scenario in that case, otherwise I can really only provide information on what this method is for because it highly depends what you are using in the script.

                Please let me know if I may be of additional assistance.
                Appreciate the elaborate response, Jesse. Per your quoted example - this is making sense now although I would never build that dependency into my strategy. Everything pertaining to managing logs from/to Google docs is contained in my DLL. Meaning my service is being called via a thread which then runs in the background. It connects, logs the data, and then cleans up any open connections. The threading is handled in its own method per the many examples one can find online. So the overriden thread methods clean up properly. That is how it should be built IMO.

                However, that said, I get where you are coming from. Had I not written this stuff in a separate DLL then this may have been a good approach. Which is perhaps why I got confused when I saw this paragraph in your docs.

                Anyway, you guys are busy and perhaps it's better to shelf this discussion for now and leave you to attend more important matters

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by fiddich, Today, 05:25 PM
                0 responses
                0 views
                0 likes
                Last Post fiddich
                by fiddich
                 
                Started by gemify, 11-11-2022, 11:52 AM
                6 responses
                803 views
                2 likes
                Last Post ultls
                by ultls
                 
                Started by ScottWalsh, Today, 04:52 PM
                0 responses
                4 views
                0 likes
                Last Post ScottWalsh  
                Started by ScottWalsh, Today, 04:29 PM
                0 responses
                7 views
                0 likes
                Last Post ScottWalsh  
                Started by rtwave, 04-12-2024, 09:30 AM
                2 responses
                22 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Working...
                X