Use waitforstatuschange in a loop