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 NullPointStrategies, Today, 05:17 AM
    0 responses
    51 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    128 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X