There are a bunch of compressed pieces of data that should be deflated asynchronously - without blocking or slowing down the main stream in any form or form.
Decompressed pieces will be used by the main thread as soon as they are unpacked.
I am currently doing it like this:
foreach (var chunkPair in compressedChunkData)
{
var task = Task.Factory.StartNew<Chunk>(() =>
{
var compressedBytes = Convert.FromBase64String(chunkPair.Value);
var chunk = Decompress(compressedBytes);
return chunk;
}).ContinueWith((finishedTask) =>
{
var chunk = finishedTask.Result;
TaskFinishActions.Enqueue(() =>
{
chunk.PostSerialize();
document.Chunks.Add(chunkPair.Key, chunk);
});
});
}
The problem is that it seems to capture the kernel that mainthread is running on, it improves performance.
Is there a way to TaskFactoryhave a thread to the kernel and a context switch from mainthread only in those short moments when mainthread is locked?
EDIT: foreach , , , mainthread .
EDIT2: , :
- , 250 ,
compressedChunkData - 10 , 12, 0, 2 ..