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

Help with debugging ideas

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

    Help with debugging ideas

    Hello,

    I created an AddOn that adds custom controls to ChartTrader per ChartTab... the way I did this was to create multiple of the same objects and then show/hide them as the user switches back and forth between tabs. I know what I have is neither concise or elegant, but I can open/close charts, open/close tabs, switch tabs, switch workspaces, etc and I'm getting my desired functionality out of it. Except for this error below.

    When I go to the Control Center and go to Tools > Options and click OK, I get the "The calling thread cannot access this object because a different thread owns it." message.

    This very specifically only happens when I click OK from the Tools>Options window. If I click cancel, there's no error and I don't get errors from opening any other windows/menus anywhere in the app.

    My problem is that this exception is not caught by the Visual Studio debugger, I could put break points on every line of my code, it's not executing when this happens, nor is it triggering any of the debugging statements in my code. I can't find a way to trace the source of it.

    Does anyone have any recommendations for how to trace the source of this? I'm down to the point where I've started with a blank slate and are adding chunks of code back in one at a time...which sucks obviously...there's 1000+ lines of code.

    #2
    I guess I should add that I'm assuming this is caused by threading issues tied to UI element modification, but I can't tell what isn't correct. I've already wrapped everything modifying the UI in a Dispatcher.Invoke() using either the dispatcher of the ChartWindow or the object itself (checkbox,textbox).

    Comment


      #3
      Hello NickyD,

      Thanks for your post.

      I may suggest keeping things simple and to start with an AddOn that performs one simple UI modification across all chart windows.

      If you loop through all chart windows, you could then use the dispatcher from each chart to perform the chart specific WPF modifications.

      With our examples, we have found it to be easier to incorporate the logic within an indicator, so the window modifications are made from the window's UI thread. We do not have an example to share for injecting the modifications via an AddOn.

      WPF modifications sample - https://ninjatrader.com/support/help...ui)-modifi.htm

      Looping through all windows, and using the window's dispatcher:

      Code:
      foreach (var window in NinjaTrader.Core.Globals.AllWindows)
      {
          // check if the found window is a Chart window, if not continue looking
          if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
      
          window.Dispatcher.InvokeAsync(new Action(() =>
          {
              // Modifications to specific chart window here
      
          }));
      }
      JimNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by mjairg, 07-20-2023, 11:57 PM
      3 responses
      213 views
      1 like
      Last Post PaulMohn  
      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
      4 responses
      544 views
      0 likes
      Last Post PaulMohn  
      Started by GLFX005, Today, 03:23 AM
      0 responses
      3 views
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      12 views
      0 likes
      Last Post XXtrader  
      Started by Waxavi, Today, 02:10 AM
      0 responses
      7 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Working...
      X