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 Mindset, 04-21-2026, 06:46 AM
|
0 responses
57 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
78 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
41 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
101 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
61 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|

Comment