Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cross Thread Problem?

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

    Cross Thread Problem?

    I'm using ChartTraderCustomButtonsExample coded by Chelsea Bell. I want to control one of the buttons from OnBarUpdate()


    protected override void OnBarUpdate()
    {
    if (enTrade)
    {
    buttonsArray[0].Foreground = Brushes.Black;
    if (!greenLight )
    {
    buttonsArray[0].Background = Brushes.Yellow;
    }
    else buttonsArray[0].Background = Brushes.LightGreen;

    if (!greenLight) EnterLongStopMarket(aL2[0]);
    else EnterShortStopMarket(aL[0] - TickSize);
    }

    }

    When this method is called I get "Strategy 'ChartTraderCustomButtonsExample': Error on calling 'OnBarUpdate' method on bar 2406: The calling thread cannot access this object because a different thread owns it"

    How should I code this correctly?

    #2
    Hello boreland,

    Thanks for your post.

    You will want to use a dispatcher to modify UI elements from OnBarUpdate.

    Code:
    ChartControl.Dispatcher.InvokeAsync(() =>
    {
        // Code to modify UI elements here
    });


    We look forward to assisting.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    47 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X