The docs for HttpCreateRequestQueue state that
The handle to the request queue created by HttpCreateRequestQueue must be closed by calling HttpCloseRequestQueue before the application terminates or when the session is no longer required.
Similarly, the docs for HttpCloseRequestQueue say
Applications should not call CloseHandle on the request queue handle; instead, they should call HttpCloseRequestQueue to ensure that all the resources are released.
The problem is that the SafeHandle created by the generator is a SafeFileHandle which calls CloseHandle which directly goes against the docs guidance.
Ideally, the generated code would use a custom SafeHandle implementation that overrides SafeHandle.ReleaseHandle with a call to HttpCloseRequestQueue so we wouldn't need to do something like:
PInvoke.HttpCreateRequestQueue(
HttpApi.Version,
requestQueueName,
SecurityAttributes: default,
flags,
out requestQueueHandle);
PInvoke.HttpCloseRequestQueue(requestQueueHandle);
// Avoid SafeHandle double disposing since we already called HttpCloseRequestQueue
requestQueueHandle.SetHandleAsInvalid();
The docs for
HttpCreateRequestQueuestate thatSimilarly, the docs for HttpCloseRequestQueue say
The problem is that the
SafeHandlecreated by the generator is aSafeFileHandlewhich callsCloseHandlewhich directly goes against the docs guidance.Ideally, the generated code would use a custom
SafeHandleimplementation that overridesSafeHandle.ReleaseHandlewith a call toHttpCloseRequestQueueso we wouldn't need to do something like: