You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

25 lines
863 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using Microsoft.Extensions.Hosting;
  7. namespace DotNetCore.CAP.Test.Helpers
  8. {
  9. public static class TestHostedServiceExtensions
  10. {
  11. public static void StartHostedServices(this IServiceProvider serviceProvider, CancellationToken cancellationToken)
  12. {
  13. Task.Run(async () =>
  14. {
  15. var hostedServices = serviceProvider.GetRequiredService<IEnumerable<IHostedService>>();
  16. foreach (var hostedService in hostedServices)
  17. {
  18. await hostedService.StartAsync(cancellationToken);
  19. }
  20. }, cancellationToken)
  21. .GetAwaiter().GetResult();
  22. }
  23. }
  24. }