protected override void OnBarUpdate()
{
if (buttonsArray == null)
return;
if (Global.SelectedTradeDirection == Global.Direction.LONG)
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() =>
{
buttonsArray[SHORT_BUTTON].Background = new SolidColorBrush(Colors.Transparent);
});
ForceRefresh();
}
else if (Global.SelectedTradeDirection == Global.Direction.SHORT)
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() =>
{
buttonsArray[LONG_BUTTON].Background = new SolidColorBrush(Colors.Transparent);
});
ForceRefresh();
}
else
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() =>
{
buttonsArray[LONG_BUTTON].Background = new SolidColorBrush(Colors.Transparent);
buttonsArray[SHORT_BUTTON].Background = new SolidColorBrush(Colors.Transparent);
});
ForceRefresh();
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How would I resolve thread owning issue in OnBarUpdate?
Collapse
X
-
How would I resolve thread owning issue in OnBarUpdate?
I'm newer to the UI things and would like the buttons to change color based on a trade direction, but I'm stuck on a thread issue where it cannot access the buttonsArray because a different thread owns it. I tried CurrentDispatcher.Invoke without any success. Any other ideas to get this to work?
Code:Tags: None
-
I resolved it.
Code:protected override void OnBarUpdate() { if (buttonsArray == null) return; if (buttonsArray[LONG_BUTTON] == null || buttonsArray[SHORT_BUTTON] == null) return; if (Global.SelectedTradeDirection == Global.Direction.LONG) { if (buttonsArray[SHORT_BUTTON].Dispatcher.CheckAccess()) { ResetShortButton(); } else { this.Dispatcher.InvokeAsync(new Action(() => { ResetShortButton(); })); } ForceRefresh(); } else if (Global.SelectedTradeDirection == Global.Direction.SHORT) { if (buttonsArray[LONG_BUTTON].Dispatcher.CheckAccess()) { ResetLongButton(); } else { this.Dispatcher.InvokeAsync(new Action(() => { ResetLongButton(); })); } ForceRefresh(); } else { if (buttonsArray[SHORT_BUTTON].Dispatcher.CheckAccess()) { ResetLongButton(); ResetShortButton(); } else { this.Dispatcher.InvokeAsync(new Action(() => { ResetLongButton(); })); this.Dispatcher.InvokeAsync(new Action(() => { ResetShortButton(); })); } ForceRefresh(); } }Last edited by tonystarks; 11-11-2022, 08:24 AM.
- Likes 1
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CaptainJack, 05-29-2026, 05:09 AM
|
0 responses
235 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 05:09 AM
|
||
|
Started by CaptainJack, 05-29-2026, 12:02 AM
|
0 responses
150 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 12:02 AM
|
||
|
Started by charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
162 views
1 like
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
243 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
198 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|

Comment