added timeout behavior to WaitForSingleEvent