public TransferContext(Socket listener, int _id = -1, bool withStream = false)
        {
            this._listener = listener;
            if (withStream)
            {
                this.instream  = new DealStream(listener);
                this.outstream = new DealStream(listener);
            }

            GCHandle gc = GCHandle.Alloc(messagebuffer, GCHandleType.Pinned);

            messageBufferHandler = GCHandle.ToIntPtr(gc);
            messageBufferAddress = gc.AddrOfPinnedObject();
            gc = GCHandle.Alloc(headerbuffer, GCHandleType.Pinned);
            headerBufferHandler = GCHandle.ToIntPtr(gc);
            headerBufferAddress = gc.AddrOfPinnedObject();

            this.id               = _id;
            this.Close            = false;
            this.Denied           = false;
            this.ObjectPosition   = 0;
            this.ObjectsLeft      = 0;
            this.DeserialPacketId = 0;
            this.SerialPacketSize = 0;
            this.SendMessage      = true;
            this.ReceiveMessage   = true;
            this.disposed         = true;

            HeaderSentNotice.Reset();
            HeaderReceivedNotice.Reset();
            MessageSentNotice.Reset();
            MessageReceivedNotice.Reset();
            BatchesReceivedNotice.Reset();
        }
        public void Dispose()
        {
            if (!disposed)
            {
                sb.Clear();
                msSend.Dispose();
                msReceive.Dispose();
                GCHandle gc;
                lock (binReceive)
                {
                    if (!binReceiveHandler.Equals(IntPtr.Zero))
                    {
                        gc = GCHandle.FromIntPtr(binReceiveHandler);
                        gc.Free();
                    }
                    binReceive = null;
                }
                lock (binSend)
                {
                    if (!binSendHandler.Equals(IntPtr.Zero))
                    {
                        gc = GCHandle.FromIntPtr(binSendHandler);
                        gc.Free();
                    }
                    binSend = null;
                }

                gc = GCHandle.FromIntPtr(messageBufferHandler);
                gc.Free();
                messagebuffer = null;
                gc            = GCHandle.FromIntPtr(headerBufferHandler);
                gc.Free();
                headerbuffer = null;

                HeaderSentNotice.Dispose();
                HeaderReceivedNotice.Dispose();
                MessageSentNotice.Dispose();
                MessageReceivedNotice.Dispose();
                BatchesReceivedNotice.Dispose();

                disposed = true;
            }
        }