Added code path to detach thread, if CloseHandle is called for a running thread.