replaced thread.sleep with a WaitOne on a ManualResetEvent