- ago
Using B125.
I use Windows MessageBox in some of my strategies. On running one yesterday I noticed that the box opened in the background, behind WealthLab. It *always* used to open in the foreground, on top of all windows.
Is this a Windows or WealthLab issue?

P.S. Some of my strategies use InputBox also, which is opening correctly in the foreground, as always.
1
66
Solved
2 Replies

Reply

Bookmark

Sort
Glitch8
 ( 9.82% )
- ago
#1
Strategies are executed in a separate thread, so if you want to use MessageBox in a Strategy you need to carefully consider this. Here's a pattern that shows the MessageBox on the UI thread, and suspends the execution of the Initialize method until after the user clicks OK.

CODE:
public override void Initialize(BarHistory bars) {          bool canContinue = false;          ThreadUtils.ThreadSafe(new Action(() =>          {             MessageBox.Show("Box");             canContinue = true;          }));          while(!canContinue)          {             Thread.Sleep(100);          } }
0
Best Answer
- ago
#2
Working great... thanks!
---------------------

It's strange, though... I've used System.Windows.MessageBox.Show(Msg) for years w/o issue and then this happened... must've been some recent Windows Update.
0

Reply

Bookmark

Sort