Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The calling thread cannot access this object because a different thread owns it.

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

  • koganam
    replied
    Originally posted by -=Edge=- View Post
    Interesting... kind of a pain for all the colors I declare, but that works!

    Thank You Very Much!


    We probably need to have this in the NT documentation? No?

    Leave a comment:


  • -=Edge=-
    replied
    Originally posted by koganam View Post
    Try freezing the new SolidBrush() first.
    Interesting... kind of a pain for all the colors I declare, but that works!

    Thank You Very Much!


    Leave a comment:


  • koganam
    replied
    Originally posted by -=Edge=- View Post
    How are you declaring your upBrush.. with Brushes.Color or with new SolidBrush?

    I'm running into the same issue/error with the calling thread.. I'm trying to declare a Brush by using new SolidBrush vs Brushes.Color with a drawobject.. I'm doing this as I want to be able to use ARGB and/or RGB for defining the color..

    Here is simple script.. Drawing/ReDrawing a Dot at the high of everybar.. One bool property to choose between using SolidBrush or Brushes.. Throw this on one min chart.. At the close of the first real time bar you will get a calling thread error, as well as on every subsequent bar.. (I'm not sure why this only throws an error after the close of the first real time bar, as in my other project, it's throwing an error historically as well) Now after confirming the exception, Go into properties and turn off the useSolidBrush bool.. There is not problem when using the standard Brush..

    Should this be expected? or is this not allowed? or am I doing something wrong?


    Try freezing the new SolidBrush() first.

    Leave a comment:


  • -=Edge=-
    replied
    Originally posted by NJA_MC View Post
    I have seen this error a lot and know some are my issue trying to access the wrong thing after it is initialized. But here I am trying to access the PlotBrushes[] and seem to get the error that follows: (Note Displacement=0 )
    Code:
    if (sessionBar == 1 && gap0)
     PlotBrushes[0][-Displacement] = Brushes.Transparent;
     elseif (SessionVWAP[0] > SessionVWAP[1])
     PlotBrushes[0][-Displacement] = upBrush;
     elseif (SessionVWAP[0] < SessionVWAP[1])
     PlotBrushes[0][-Displacement] = downBrush;
     elseif(sessionBar == 2 && gap0)
     PlotBrushes[0][-Displacement] = upBrush;
     else
    PlotBrushes[0][-Displacement] = PlotBrushes[0][1-Displacement];
     if(sessionBar == 1 && gap1)
     {
     for (int i = 1; i <= 6; i++)
     PlotBrushes[i][-Displacement] = Brushes.Transparent;
     }
    Here is the error produced, and note, it isn't all the time.... That is the part making this debugging difficult.
    System.InvalidOperationException occurred
    HResult=-2146233079
    Message=The calling thread cannot access this object because a different thread owns it.
    Source=WindowsBase
    StackTrace:
    at System.Windows.Threading.DispatcherObject.VerifyAc cess()
    at System.Windows.Freezable.Freeze(Boolean isChecking)
    at NinjaTrader.NinjaScript.BrushSeries.Set(Int32 index, Brush value)
    at NinjaTrader.NinjaScript.Indicators.anaCurrentDayVW APV43.OnBarUpdate() in c:\Users\Greg\Documents\NinjaTrader 8\bin\Custom\Indicators\anaCurrentDayVWAPV43.cs:li ne 706
    InnerException:

    So is this assignment not allowed!?!?
    How are you declaring your upBrush.. with Brushes.Color or with new SolidBrush?

    I'm running into the same issue/error with the calling thread.. I'm trying to declare a Brush by using new SolidBrush vs Brushes.Color with a drawobject.. I'm doing this as I want to be able to use ARGB and/or RGB for defining the color..

    Here is simple script.. Drawing/ReDrawing a Dot at the high of everybar.. One bool property to choose between using SolidBrush or Brushes.. Throw this on one min chart.. At the close of the first real time bar you will get a calling thread error, as well as on every subsequent bar.. (I'm not sure why this only throws an error after the close of the first real time bar, as in my other project, it's throwing an error historically as well) Now after confirming the exception, Go into properties and turn off the useSolidBrush bool.. There is not problem when using the standard Brush..

    Should this be expected? or is this not allowed? or am I doing something wrong?


    Attached Files

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    Hello NJA_MC,

    Thank you for your post.

    This assignment is allowed, it appears that the UI thread is not holding the NinjaScript object and somewhere we are seeing an issue is calling the brush to the UI or vice versa.

    Would you mind sending over your workspaces and the indicator you are testing to platformsupport[at]ninjatrader[dot]com?

    Leave a comment:


  • The calling thread cannot access this object because a different thread owns it.

    I have seen this error a lot and know some are my issue trying to access the wrong thing after it is initialized. But here I am trying to access the PlotBrushes[] and seem to get the error that follows: (Note Displacement=0 )
    Code:
    if (sessionBar == 1 && gap0)
     PlotBrushes[0][-Displacement] = Brushes.Transparent;
     elseif (SessionVWAP[0] > SessionVWAP[1])
     PlotBrushes[0][-Displacement] = upBrush;
     elseif (SessionVWAP[0] < SessionVWAP[1])
     PlotBrushes[0][-Displacement] = downBrush;
     elseif(sessionBar == 2 && gap0)
     PlotBrushes[0][-Displacement] = upBrush;
     else
    PlotBrushes[0][-Displacement] = PlotBrushes[0][1-Displacement];
     if(sessionBar == 1 && gap1)
     {
     for (int i = 1; i <= 6; i++)
     PlotBrushes[i][-Displacement] = Brushes.Transparent;
     }
    Here is the error produced, and note, it isn't all the time.... That is the part making this debugging difficult.
    System.InvalidOperationException occurred
    HResult=-2146233079
    Message=The calling thread cannot access this object because a different thread owns it.
    Source=WindowsBase
    StackTrace:
    at System.Windows.Threading.DispatcherObject.VerifyAc cess()
    at System.Windows.Freezable.Freeze(Boolean isChecking)
    at NinjaTrader.NinjaScript.BrushSeries.Set(Int32 index, Brush value)
    at NinjaTrader.NinjaScript.Indicators.anaCurrentDayVW APV43.OnBarUpdate() in c:\Users\Greg\Documents\NinjaTrader 8\bin\Custom\Indicators\anaCurrentDayVWAPV43.cs:li ne 706
    InnerException:

    So is this assignment not allowed!?!?
    Attached Files

Latest Posts

Collapse

Topics Statistics Last Post
Started by kinfxhk, 07-13-2026, 10:18 AM
0 responses
30 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by kinfxhk, 07-13-2026, 09:50 AM
0 responses
24 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by kinfxhk, 07-13-2026, 07:21 AM
0 responses
30 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by kinfxhk, 07-11-2026, 02:11 AM
0 responses
27 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by SalmaTrader, 07-07-2026, 10:26 PM
0 responses
141 views
0 likes
Last Post SalmaTrader  
Working...
X