【问题标题】:Is IHostedService.StopAsync() called when IIS recycles?IIS 回收时是否调用 IHostedService.StopAsync()?
【发布时间】:2019-06-14 15:48:13
【问题描述】:

这个问题是关于在 IIS 上运行的 ASP.NET Core 2.2 应用程序,特别是在向 DI 容器注册 IHostedService 的实例时。

我读到的每一篇关于IHostedService.StopAsync() 的文章都只是谈到了StopAsync() 在主机“关闭”时被调用,但我想知道当 IIS 回收时会发生什么。

我的问题:

1. IIS 回收时是否调用了StopAsync()

2。无论使用InProcess 托管还是OutOfProcess 托管,答案是否相同?(ASP.NET Core 从版本 2.2 开始支持InProcess

【问题讨论】:

    标签: iis dependency-injection asp.net-core-2.2 asp.net-core-hosted-services


    【解决方案1】:
    1. IIS 回收时是否调用StopAsync()

    是的

    参考Implement background tasks in microservices with IHostedService and the BackgroundService class

    部署注意事项和要点

    请务必注意部署 ASP.NET Core 的方式 WebHost 或 .NET Core Host 可能会影响最终解决方案。为了 例如,如果您将 WebHost 部署在 IIS 或常规 Azure 应用程序上 服务,您的主机可能会因为应用程序池回收而被关闭。

    .....

    注意:强调我的

    通过扩展将停止任何IHostedService

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 2020-12-04
      • 2016-12-17
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      相关资源
      最近更新 更多