I have a lot of operations what i want to run async. I do:
var tasks = new List<Task<bool>>();
for(var i=0;i<1000;i++){
tasks.Add(CreateGeoreferencedImageAsync(properties, scaleIndex, currentXmin, currentYmin, currentXmax, currentYmax));
}
while (tasks.Count > 0)
{
var bunch = tasks.Take(4).ToList();
bool[] firstFinishedTask = await Task.WhenAll(bunch);
tasks.RemoveRange(0,4);
}
But i see that WhenAll
execute all Task from tasks
not only from bunch
.
What i missed?
UPDATE
private Task<bool> CreateGeoreferencedImageAsync(ImageGenerationProperties
properties, int scaleIndex,
double currentXmin, double currentYmin, double currentXmax, double currentYmax)
{
return Task.Run(() =>
{
return CreateGeoreferencedImage(properties, scaleIndex, currentXmin, currentYmin, currentXmax,
currentYmax);
});
}