예제 #1
0
        public void Dispose()
        {
            lock (_buffer)
            {
                if (!_disposed)
                {
                    _waitReadable.Dispose();
                    _waitWriteable.Dispose();

                    _reader.Dispose();
                    _writer.Dispose();

                    ChannelsRepository.RemoveNamedReader <T>(Name, _reader);
                    ChannelsRepository.RemoveNamedWriter <T>(Name, _writer);

                    _disposed = true;
                }
            }
        }
예제 #2
0
        public NamedChannel(string name, int bufferSize)
        {
            if (bufferSize <= 0)
            {
                throw new ArgumentException(string.Format("bufferSize must be greater than 0. bufferSize={0}", bufferSize));
            }

            _buffer     = new Queue <T>(bufferSize);
            _bufferSize = bufferSize;

            _waitReadable  = new ManualResetEvent(false);
            _waitWriteable = new ManualResetEvent(true);

            _reader = new Impl.ChannelReader <T>(_buffer, _bufferSize, _waitReadable, _waitWriteable);
            _writer = new ChannelWriter <T>(_buffer, bufferSize, _waitReadable, _waitWriteable);

            Name = name;

            ChannelsRepository.AddNamedReader <T>(name, _reader, _buffer);
            ChannelsRepository.AddNamedWriter <T>(name, _writer, _buffer);
        }