I've got to select an item from a context menu for a particular case, but the item doesn't become available for an undetermined period of time whislt other processing occurs in the background.

I've written a (very)basic function to handle re-selecting if it's not there the first time, but how do I get it to repeat until the menu item is selected? I should know this, but am having a real mental block today!

Attach "XXXMainWindow"
Replay.Pausemode = 1
Pause 10
Replay.Pausemode = 0
DataWindow "Window", "dw_XXXXX", 'Right SingleClick'
PopupMenuSelect "MenuSelection"