public void Terminate() { if (ContextHandle == IntPtr.Zero) { return; } while (LibZmq.zmq_term(ContextHandle) != 0) { int errorCode = ErrorProxy.GetErrorCode(); // If zmq_term fails, valid return codes are EFAULT or EINTR. If EINTR is set, termination // was interrupted by a signal and may be safely retried. if (errorCode == ErrorCode.EFAULT) { // This indicates an invalid context was passed in. There's nothing we can do about it here. // It's arguably not a fatal error, so throwing an exception would be bad seeing as this may // run inside a finalizer. break; } } ContextHandle = IntPtr.Zero; }