In general, never use TerminateThread
because you can leave locks held and cause all sorts of problems. As MSDN says:
What you can do instead is to make your thread wait on an event object, which you can use to signal termination from another thread.
If you need to perform a periodic check for a terminate signal within some normal thread processing, you can set a wait timeout of zero so your thread can do still work while waiting to be terminated.
An example is in this SO answer here.