CWinThread invalidates the handle when the thread ceases to exist. That would explain it.