Using event-wait instead of sleep() in application main loop