Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

SleepMiddleware.cs 733B

1234567891011121314151617181920212223242526272829
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.Extensions.Options;
  5. using WebApiWebSem.Dbo;
  6. namespace WebApiWebSem.Middleware
  7. {
  8. public class SleepMiddleware
  9. {
  10. private readonly RequestDelegate _next;
  11. private readonly AppConfigDbo _options;
  12. public SleepMiddleware(RequestDelegate next, IOptions<AppConfigDbo> options)
  13. {
  14. _next = next;
  15. _options = options.Value;
  16. }
  17. public async Task Invoke(HttpContext context)
  18. {
  19. if (_options.SleepTime > 0)
  20. {
  21. Thread.Sleep(_options.SleepTime);
  22. }
  23. await _next.Invoke(context);
  24. }
  25. }
  26. }