public void WaitForStop( ) { Thread tempThread = null; lock ( sync ) { tempThread = thread; } if ( tempThread != null ) { // wait for thread stop tempThread.Join( ); Free( ); } }