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, 05-11-2026, 05:56 AM
    0 responses
    52 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    29 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    194 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    355 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    274 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X