unsafe void StartReceive(bool synchronously) { bool useCompletionPort; try { this.handle = this.msmqQueue.GetHandleForAsync(out useCompletionPort); } catch (MsmqException ex) { OnCompletion(ex.ErrorCode, synchronously); return; } if (null != nativeOverlapped) { Fx.Assert("---- in StartReceive"); } IntPtr nativePropertiesPointer = this.message.Pin(); nativeOverlapped = new Overlapped(0, 0, IntPtr.Zero, this).UnsafePack(onPortedCompletion, this.message.GetBuffersForAsync()); int error; try { if (useCompletionPort) { error = msmqQueue.ReceiveCoreAsync(this.handle, nativePropertiesPointer, this.timeoutHelper.RemainingTime(), this.action, nativeOverlapped, null); } else { if (onNonPortedCompletion == null) { onNonPortedCompletion = new UnsafeNativeMethods.MQReceiveCallback(OnNonPortedCompletion); } error = msmqQueue.ReceiveCoreAsync(this.handle, nativePropertiesPointer, this.timeoutHelper.RemainingTime(), this.action, nativeOverlapped, onNonPortedCompletion); } } catch (ObjectDisposedException ex) { // if Close ----s with the async Receive, it is possible that SafeHandle will throw ObjectDisposedException // the behavior should be same as if operation was just cancelled (the channel will return no message) MsmqDiagnostics.ExpectedException(ex); error = UnsafeNativeMethods.MQ_ERROR_OPERATION_CANCELLED; } if (error != 0) { if (error != UnsafeNativeMethods.MQ_INFORMATION_OPERATION_PENDING) { Overlapped.Free(nativeOverlapped); nativeOverlapped = null; GC.SuppressFinalize(this); OnCompletion(error, synchronously); } } }
unsafe int ReceiveCoreAsync(MsmqQueueHandle handle, IntPtr nativePropertiesPointer, TimeSpan timeout, int action, NativeOverlapped *nativeOverlapped, UnsafeNativeMethods.MQReceiveCallback receiveCallback) { int timeoutInMilliseconds = TimeoutHelper.ToMilliseconds(timeout); return(UnsafeNativeMethods.MQReceiveMessage(handle, timeoutInMilliseconds, action, nativePropertiesPointer, nativeOverlapped, receiveCallback, IntPtr.Zero, (IntPtr)UnsafeNativeMethods.MQ_NO_TRANSACTION)); }
private unsafe void StartReceive(bool synchronously) { bool flag; int num; try { this.handle = this.msmqQueue.GetHandleForAsync(out flag); } catch (MsmqException exception) { this.OnCompletion(exception.ErrorCode, synchronously); return; } NativeOverlapped *nativeOverlapped = this.nativeOverlapped; IntPtr nativePropertiesPointer = this.message.Pin(); this.nativeOverlapped = new Overlapped(0, 0, IntPtr.Zero, this).UnsafePack(onPortedCompletion, this.message.GetBuffersForAsync()); try { if (flag) { num = this.msmqQueue.ReceiveCoreAsync(this.handle, nativePropertiesPointer, this.timeoutHelper.RemainingTime(), this.action, this.nativeOverlapped, null); } else { if (onNonPortedCompletion == null) { onNonPortedCompletion = new UnsafeNativeMethods.MQReceiveCallback(MsmqQueue.TryReceiveAsyncResult.OnNonPortedCompletion); } num = this.msmqQueue.ReceiveCoreAsync(this.handle, nativePropertiesPointer, this.timeoutHelper.RemainingTime(), this.action, this.nativeOverlapped, onNonPortedCompletion); } } catch (ObjectDisposedException exception2) { MsmqDiagnostics.ExpectedException(exception2); num = -1072824312; } if ((num != 0) && (num != 0x400e0006)) { Overlapped.Free(this.nativeOverlapped); this.nativeOverlapped = null; GC.SuppressFinalize(this); this.OnCompletion(num, synchronously); } }
private unsafe int ReceiveCoreAsync(MsmqQueueHandle handle, IntPtr nativePropertiesPointer, TimeSpan timeout, int action, NativeOverlapped *nativeOverlapped, UnsafeNativeMethods.MQReceiveCallback receiveCallback) { int num = TimeoutHelper.ToMilliseconds(timeout); return(UnsafeNativeMethods.MQReceiveMessage(handle, num, action, nativePropertiesPointer, nativeOverlapped, receiveCallback, IntPtr.Zero, IntPtr.Zero)); }