Justin
Justin

Reputation: 86759

What implementation of SafeHandle should I use for process handles?

This afternoon has been a crash course for me in terms of handles, Safe handles, PInvoke and many other things. I think its slowly sinking in, however I'm still struggling with a couple of concepts:

How do I know what implementation of SafeHandle I should use with different handle types?

Specifically, what implementation of SafeHandle should I use with process handles (such as those in the PROCESS_INFORMATION structure returned from a call to CreateProcess?

The only two public implementations that I can see are SafeFileHandle and SafeWaitHandle - neither of these seem to be appropriate in this case.

Which should I use?

Upvotes: 4

Views: 1170

Answers (1)

Hans Passant
Hans Passant

Reputation: 941873

SafeWaitHandle is the appropriate one. A process handle is in fact a waitable handle. You can call WaitForSingleObject() on it and it will block until the process terminates. The ReleaseHandle method calls CloseHandle(), as required. Are you sure that the Process class doesn't already do what you need?

Upvotes: 7

Related Questions