Added WaitForShutdown method

Refactored code to create WaitForShutdown from the Dispose method