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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X