Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Where should I put Brush.Freeze()
Collapse
X
-
You do not need to .Freeze() unaltered brushes that are user input parameters as the platform takes care of that for you.
You also do not need to .Freeze() hardcoded constants that are merely another reference to a predefined brush e.g. SolidColorBrush MyBrush = Brushes.Red as these are pointers to an already frozen predefined brush.
If you alter them (for instance, reducing their alpha) or create new ones, you probably do that in State.Configure (or possibly later if you have a reason), and when you create them you should then .Freeze() them before they get used.Last edited by QuantKey_Bruce; 03-21-2023, 06:02 AM.
-
Hello alanlopen,
Thanks for your post.
Brush.Freeze() would not need to be called on pre-defined brushes. The advantage to using these brushes is that they are readily available, properly named to quickly find a simple color value, and can be reused on-the-fly without having to recreate an instance of the brush at run time, and do not need to be otherwise managed.
If you want to use a more specific color than the pre-defined brushes offer, you will need to initiate your own custom brush object, where you can then specify your color using RGB (red, green, blue) values Color.FromRgb(). Anytime you create a custom brush that will be used by NinjaTrader rendering it must be frozen using the .Freeze() method due to the multi-threaded nature of NinjaTrader.
Note that if you do not call .Freeze() on a custom-defined brush then it will eventually result in threading errors should you try to modify or access that brush after it is defined.
See the help guide documentation below for more information about working with brushes and sample code.
Working with brushes: https://ninjatrader.com/support/help...th_brushes.htm
Please let me know if I may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
yes I was talking about custom brushes like from Color.FromRgb(). Those must be frozen in else if(State==State.Configure) ?
Comment
-
Hello alanlopen,
Thanks for your note.
Brush.Freeze() should be called after the brushes are constructed. If you are constructing the brushes in State.Configure, then you would call Brush.Freeze() right after constructing the brushes.
See this help guide page for more information about using custom brushes: https://ninjatrader.com/support/help...ightsub=Freeze
Please let me know if you have further questions about this.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
576 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment