Ejemplo n.º 1
0
        private async Task StartInternal()
        {
            var cancellationToken = _cancellationToken;

            try
            {
                while (true)
                {
                    var result = Dequeue();
                    if (result != null)
                    {
                        await _outputStream.WriteAsync(result.Item1, result.Item2, result.Item3, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await Task.Delay(50, cancellationToken).ConfigureAwait(false);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
            }
            finally
            {
                OnClosed();
            }
        }
Ejemplo n.º 2
0
        private async Task StartInternal()
        {
            var cancellationToken = _cancellationToken;

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    _isActive = true;

                    var bytes = Dequeue();
                    if (bytes != null)
                    {
                        await _outputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await Task.Delay(50, cancellationToken).ConfigureAwait(false);
                    }
                }

                TaskCompletion.TrySetResult(true);
                _logger.Debug("QueueStream complete");
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
            }
            finally
            {
                _isActive = false;

                if (OnFinished != null)
                {
                    OnFinished(this);
                }
            }
        }
Ejemplo n.º 3
0
        public void Write(byte[] bytes, int offset, int count)
        {
            //return _outputStream.WriteAsync(bytes, offset, count, cancellationToken);

            try
            {
                _outputStream.Write(bytes, offset, count);
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
                OnClosed();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
                OnClosed();
            }
        }
Ejemplo n.º 4
0
        public async Task WriteAsync(byte[] bytes, int offset, int count)
        {
            //return _outputStream.WriteAsync(bytes, offset, count, cancellationToken);
            var cancellationToken = _cancellationToken;

            try
            {
                await _outputStream.WriteAsync(bytes, offset, count, cancellationToken).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("QueueStream cancelled");
                TaskCompletion.TrySetCanceled();
                OnClosed();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in QueueStream", ex);
                TaskCompletion.TrySetException(ex);
                OnClosed();
            }
        }