Example #1
0
        /// <summary>
        /// Initialise the members.
        /// </summary>
        private void Init()
        {
            _waitTime   = TimeSpan.FromSeconds(1);
            _readyState = WebSocketConnectionState.Open;

            _messageEventQueue = new Queue <MessageEventArgs>();
            _receiveResult     = new ReceiveResultWebContext()
            {
                ReturnComplete = true
            };
            _lockEnqueue = ((ICollection)_messageEventQueue).SyncRoot;

            if (_context != null)
            {
                // Receive data in async mode.
                _context.Context.Context.ReceivedAsyncMode = () => AsyncModeReceiver();
            }

            _exitReceiving         = new AutoResetEvent(false);
            _receivePong           = new AutoResetEvent(false);
            _recevedFrame          = new AutoResetEvent(false);
            _frameReturnedComplete = new AutoResetEvent(false);
        }
Example #2
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    if (_receivePong != null)
                    {
                        _receivePong.Dispose();
                    }

                    if (_exitReceiving != null)
                    {
                        _exitReceiving.Dispose();
                    }

                    if (_recevedFrame != null)
                    {
                        _recevedFrame.Dispose();
                    }

                    if (_frameReturnedComplete != null)
                    {
                        _frameReturnedComplete.Dispose();
                    }

                    if (_readStream != null)
                    {
                        _readStream.Dispose();
                    }

                    if (_writeStream != null)
                    {
                        _writeStream.Dispose();
                    }

                    if (_messageEventQueue != null)
                    {
                        _messageEventQueue.Clear();
                    }

                    if (_receiveResult != null)
                    {
                        _receiveResult.Result = null;
                        _receiveResult.Data   = null;
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _lockConnect = null;
                _lockReceive = null;
                _lockEnqueue = null;

                _receiveResult     = null;
                _messageEventQueue = null;

                _receivePong           = null;
                _exitReceiving         = null;
                _recevedFrame          = null;
                _frameReturnedComplete = null;

                _readStream  = null;
                _writeStream = null;

                _context = null;
            }
        }