Example #1
0
        public void Listen()
        {
            while (true)
            {
                try
                {
                    try
                    {
                        //Get a single byte
                        byte sample = _streamResource.ReadSingleByte();

                        //Raise the event
                        RaiseSampleEvent(sample);
                    }

                    catch (IOException)
                    {
                        if (_streamResource != null)
                        {
                            //_streamResource.DiscardInBuffer();
                        }
                    }
                    catch (TimeoutException)
                    {
                        _streamResource?.DiscardInBuffer();
                    }
                }
                catch (InvalidOperationException)
                {
                    // when the underlying transport is disposed
                    break;
                }
            }
        }