Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

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

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

  • NinjaTrader_ChrisL
    replied
    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.

    Leave a comment:


  • b16_aln
    replied
    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?

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • b16_aln
    replied
    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?

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • 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

Latest Posts

Collapse

Topics Statistics Last Post
Started by AaronKoRn, Today, 03:05 PM
1 response
9 views
0 likes
Last Post NinjaTrader_Emily  
Started by zacharydw00, Today, 02:21 PM
2 responses
13 views
0 likes
Last Post zacharydw00  
Started by Harvard, Today, 12:01 PM
2 responses
13 views
0 likes
Last Post Harvard
by Harvard
 
Started by DanDaMan, Today, 12:40 PM
5 responses
15 views
0 likes
Last Post NinjaTrader_Zachary  
Started by bob999, 02-16-2021, 10:00 AM
3 responses
29 views
0 likes
Last Post NinjaTrader_Kate  
Working...
X