Written code will not end up in a situation where someone closes the descriptor while someone is waiting for it because you never close the descriptor. The handle will be closed after the process is completed, but you will not wait for it (this particular descriptor) by definition.
HANDLE does not have a non-trivial destructor, so it will not close itself. This, of course, can be problematic in itself, but it is another problem that you close the handle too fast, which you seem to be worried about. I suggest you take a step back and make sure that you understand what you are trying to accomplish.
source share