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

unhandled exception : cannot access a disposed object. Object name:"Direct2DForm"

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

    unhandled exception : cannot access a disposed object. Object name:"Direct2DForm"

    Hello,

    Can anyone point me in the direction of the Object name "Direct2DForm" within NT8 so that I work out why my indicator is trying to access it after it appears to have been disposed? It's not an object that I have initiated as far as I know so I'm guessing it must realte to some of the NT8 methods.

    Thanks

    #2
    Hello b16_aln,

    Thank you for the post.

    I am not aware what this would stem from, that could potentially be a lot of different items. Direct2d is part of the rendering framework which is used in about all NinjaScript types, based on the name potentially that is the chart. Is there something specific you are doing in code when you see this happen? If you have a set of steps that reproduces the error you could comment out code in your script to further isolate what part that's coming from.

    Based on the error of accessing a disposed object this could relate to something you are doing in State.Terminated and accessing something that is disposed like a chart object.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse,

      Yes, it probably is related to a chart. I'm using a dispatcher to apply the Close() method to automatically close down a chart window. I can post some of the code when I get back on my pc.

      Do I need to do anything after the Close() method to make sure that the script is stopped on the thread? From what you've posted, my understanding is this may be relating to the chart script running on, on a different thread after the dispatcher thread has closed the window?

      Comment


        #4
        Hello b16_aln,

        There are not enough details here for me to make any suggestions other than to collect the specific steps you are using to generate the error and then isolate what code/state when the code is called in. That would give us more details on whats happening instead of guessing that you are accessing a disposed object. I could make a guess that when you are calling the Close method is not valid but I would need to see a specific example of where that code is being called and how it was used when it failed. It could also be that Close is not the correct way to close the window you are targeting, at this time there is not a specific documented Close for the NT window and we can only assume the WPF Close method can be used.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse,

          The code i'm using is

          var window = NinjaTrader.Core.Globals.AllWindows[NinjaTrader.Core.Globals.AllWindows.IndexOf(ChartC ontrol.OwnerChart)] as Chart;
          window.Dispatcher.InvokeAsync((Action)(() =>
          {
          window.Activate();
          window.Close();
          }));

          The code is effective in that the window closes however it also results in the unhandled exception : cannot access a disposed object. Object name:"Direct2DForm"

          If I use Thread.Sleep() before the the Close() method it appears to not result int he error however I am aware that Thread.Sleep() is NOT a viable options it does point me in the direction that possibly the Close() is simply occuring too quickly for the rest of the code on non-dispatcher thread to catch up?

          Comment


            #6
            Hello b16_aln, thanks for your reply.

            Unfortunately, there is nothing documented or supported that we can offer to help. It would take trial and error testing/debugging to get this to work properly. There is a lot of background work going on with Chart windows, indicator loading, etc that we do not have documented publicly, so it goes out of the scope of support we can provide.

            Best regards.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            23 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            15 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            46 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            23 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            181 views
            0 likes
            Last Post jeronymite  
            Working...
            X