public Task CopyToAsync(Stream stream) { var result = new QueueStream(stream, _logger) { OnFinished = OnFinished }; var initial = _sharedBuffer.ToList(); var list = new List <byte>(); foreach (var bytes in initial) { list.AddRange(bytes); } _logger.Info("QueueStream started with {0} initial bytes", list.Count); result.Queue(list.ToArray()); _outputStreams.TryAdd(result.Id, result); result.Start(_cancellationToken); return(result.TaskCompletion.Task); }
public void RemoveOutputStream(QueueStream stream) { lock (_outputStreams) { _outputStreams.Remove(stream); } }
public Task CopyToAsync(Stream stream) { var result = new QueueStream(stream, _logger) { OnFinished = OnFinished }; _outputStreams.TryAdd(result.Id, result); result.Start(_cancellationToken); return(result.TaskCompletion.Task); }
public Task CopyToAsync(Stream stream, CancellationToken cancellationToken) { var queueStream = new QueueStream(stream, _logger); _outputStreams.TryAdd(queueStream.Id, queueStream); try { queueStream.Start(cancellationToken); } finally { _outputStreams.TryRemove(queueStream.Id, out queueStream); GC.Collect(); } return(Task.FromResult(true)); }
private void OnFinished(QueueStream queueStream) { RemoveOutputStream(queueStream); }
public void RemoveOutputStream(QueueStream stream) { QueueStream removed; _outputStreams.TryRemove(stream.Id, out removed); }