I need to send 10,000 messages. At the moment, this happens synchronously and takes up to 20 minutes to send them to everyone.
foreach (var message in messages)
{
var result = Send(message);
_logger.Info($"Successfully sent {message.Title}.")
}
To reduce the time it takes to send a message, I would like to use async and wait, but I am worried that C # runtime can handle 15,000 tasks in a workflow.
var tasks = new List<Task>();
foreach (var message in messages)
{
tasks.Add(Task.Run(() => Send(message))
}
var t = Task.WhenAll(tasks);
t.Wait();
...
Also, in terms of memory, I'm not sure if it is a good idea to create a list of 15,000 tasks
source
share