title: C# Parallel.Foreach...Multi theading with unknown number of threads
body: <p>I have a sync process that must run on each of my businesses.  The number of businesses is ever-changing.</p>
  
  <p>I've read docs about the Thread class, Parallelism..etc...I'm not sure I understand how to do it without knowning/naming a predefined number of threads...in this case, that number is unknown. For that reason, I found Parallel.ForEach...because I wish to run an unknown number of simultaneous operations</p>
  
  <p>My sync operations run every 10 minutes.  They each take up to a minute or two to run. Obviously, I can't run them iteratively because by the time they'd finish, the next call would be triggering.</p>
  
  <p>I want to run them simultaneously in separate threads.  While they should each have unique API keys, they do not share mem or data and will not modify any shared data.</p>
  
  <p>For this, I've done some research on how to do multi-threading...I'm thinking Parallel.ForEach would do the trick...</p>
  
  <p>I need help with the syntax...</p>
  
  <p>This is in a Worker Service...I have a private method called <code>SyncBusiness(int businessId)</code> that calls an API endpoint that syncs the business.  Easy..just need help with calling the method?</p>
  
  <pre><code>protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  {
      var businessIds = (from x in _db.Poslookup
                         select x.BusinessId).Distinct();
  
      while (!stoppingToken.IsCancellationRequested)
      {
          // Want to multi-thread a sync for each of the businesses in businessIds
          Parallel.ForEach(businessIds, i =&gt; { 
              await SyncBusiness(i)
          });
  
          _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
          await Task.Delay(600000, stoppingToken);
      }
  }
  </code></pre>
  
  <p>Also, please comment on any gotchas regarding scalability, thread limits...etc....any areas where I might get into trouble if I grew to several thousand businesses to sync...perhaps suggestions on things to read about sync operations and scalability?</p>
  
  <p>Thank you so much.  Cheers.</p>