This action block is connected to a transform block with the signaturevar getStream = new TransformBlock<FileChunk, Tuple<Task<HttpResponseMessage>, FileChunk>>
however, the stream is not writing directly to the file provided. For some reason, I think that it is still being cached to memory. The Task is the tuple is initalized as client.SendAsync(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
var writeStream = new ActionBlock<Tuple<Task<HttpResponseMessage>, FileChunk>>(async task =>
{
using (var streamToRead = await task.Item1.Result.Content.ReadAsStreamAsync())
{
using (var fileToWriteTo = File.Open(task.Item2._tempfilename,
FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
await task.Item1.Result.Content.CopyToAsync(fileToWriteTo).ContinueWith(task1 =>
{
var s = new FileChunk();
Interlocked.Add(ref TasksDone, 1);
asyncTasks.TryDequeue(out s);
}, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.Current);
}
}
}, new ExecutionDataflowBlockOptions
{
BoundedCapacity = Environment.ProcessorCount, // Cap the item count
MaxDegreeOfParallelism = Environment.ProcessorCount, // Parallelize on all cores
});
Any advice on how I can fix this? Also, I am assuming that it is caching to memory first because the file size does not update or increase on refresh, rather all at once.