Check out how I did it in CompPswdAge.kix.

code:
If $frmMain.Visible $nul=Execute($frmMain.DoEvents(1)) Else Exit() EndIf