internal void StartOperationCommon(WebSocketHttpListenerDuplexStream currentStream, ThreadPoolBoundHandle boundHandle)
{
// Change status to "in-use".
if (Interlocked.CompareExchange(ref _operating, InProgress, Free) != Free)
{
// If it was already "in-use" check if Dispose was called.
if (_disposeCalled)
{
// Dispose was called - throw ObjectDisposed.
throw new ObjectDisposedException(GetType().FullName);
}
Debug.Assert(false, "Only one outstanding async operation is allowed per HttpListenerAsyncEventArgs instance.");
// Only one at a time.
throw new InvalidOperationException();
}
// HttpSendResponseEntityBody can return ERROR_INVALID_PARAMETER if the InternalHigh field of the overlapped
// is not IntPtr.Zero, so we have to reset this field because we are reusing the Overlapped.
// When using the IAsyncResult based approach of HttpListenerResponseStream the Overlapped is reinitialized
// for each operation by the CLR when returned from the OverlappedDataCache.
InitializeOverlapped(boundHandle);
_exception = null;
_bytesTransferred = 0;
}