JN
05/10/2024, 8:40 PMJN
05/10/2024, 8:40 PMforeach (...)
{
  runningTasks[indx] = new System.Threading.Tasks.Task(() =>
  {
    using (var scope = _serviceScopeFactory.CreateScope())
    {
      using (var context = _umbracoContextFactory.EnsureUmbracoContext())
      {
        // sheetItem is IPublishedContent
        var myService = scope.ServiceProvider.GetRequiredService<MyService>();
        var value = myService.DoSomething(sheetItem);
      }
    }
  }
  runningTasks[indx].Start();
  indx++;
}
System.Threading.Tasks.Task.WaitAll(runningTasks);JN
05/10/2024, 8:45 PMMatt Wise
05/10/2024, 9:51 PMJN
05/11/2024, 1:27 AMMatt Wise
05/11/2024, 5:48 AMJN
05/13/2024, 1:35 PMJN
05/13/2024, 2:39 PMusing (var context = _umbracoContextFactory.EnsureUmbracoContext())
{
  foreach (...)
  {
    runningTasks[indx] = new System.Threading.Tasks.Task(() =>
    {
      using (var scope = _serviceScopeFactory.CreateScope())
      {
          // sheetItem is IPublishedContent
          // MyService is a scoped service injected EF Context
  
          var myService = scope.ServiceProvider.GetRequiredService<MyService>();
          var value = myService.DoSomething(sheetItem);
      }
    }
  
    runningTasks[indx].Start();
    indx++;
  }
  
  System.Threading.Tasks.Task.WaitAll(runningTasks);
}JN
05/13/2024, 2:39 PMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by