title: How to run multiple threads on ASP.NET MVC efficiently?
body: <p>I've a scheduled task in my <code>ASP.NET MVC</code> site that nightly sends notifications for the users.</p>
  
  <p>I've been sending and awaiting notifications one by one, but it's taking an hour to complete now, so I thought I should send them in batches.</p>
  
  <pre><code>int counter = 0;
  List&lt;Task&gt; tasks = new List&lt;Task&gt;();
  
  foreach (var user in users)
  {
      tasks.Add(Task.Run(async () =&gt;
      {
          await user.SendNotificationAsync();
          counter++;
      }));
  
      if (tasks.Count &gt;= 20)
      {
          await Task.WhenAll(tasks);
          tasks.Clear();
      }
  }
  
  if(tasks.Any())
  {
      await Task.WhenAll(tasks);
      tasks.Clear();
  }
  </code></pre>
  
  <p>But I've read that creating multiple threads is not efficient on the servers. How should I run multiple instances of the method on the server? </p>