I am attempting to update a layout template by iterating through the text elements and changing the values of the template to something about the users map/settings.
I am able to loop through and change all the text elements, but I want to do all of the text elements at the same time. I have a list of all the elements and the changes I want to make to each of them, but they always seem to run syncronously instead of in parellel? What am i missing here? The SetTextProperties is slow so I want to do about al 50 updates in parellel?
//I have a list of object TextElementUpdate and updates to them
var tasks = new List<Task>();
foreach (TextElementUpdate teu in textElementUpdates)
{
//Shouldn't this line happen instantly and the whenall will wait?
//This line I want in parellel, so like 50 running at once, instead it is sync
tasks.Add(teu.UpdateTextElement());
}
//Wait for all the tasks to finish
await Task.WhenAll(tasks);
//-------------------------------------------------------------------
class TextElementUpdate
{
public TextElementUpdate(TextElement textElement, TextProperties textProperties)
{
TextElementToUpdate = textElement;
NewTextProperties = textProperties;
}
public TextElement TextElementToUpdate { get; set; }
public TextProperties NewTextProperties { get; set; }
public Task UpdateTextElement()
{
return QueuedTask.Run(() =>
{
TextElementToUpdate.SetTextProperties(NewTextProperties);
});
}
}