HostingEnvironment.StopListening 事件

定义

[仅在 .NET Framework 4.5.1 中受支持]

当辅助进程或与该主机相关联的应用程序池已停止侦听新的请求,并将最终关闭时才发生。

public:
 static event EventHandler ^ StopListening;
public static event EventHandler StopListening;
member this.StopListening : EventHandler 
Public Shared Custom Event StopListening As EventHandler 
Public Shared Event StopListening As EventHandler 

事件类型

注解

当应用程序池及其关联的工作进程被 IIS 关闭时,例如,当应用程序池达到计划的回收间隔时,IIS 会通知 ASP.NET 运行时应用程序正在关闭,应用程序池的工作进程将停止侦听新请求。 使用长时间运行请求的应用程序(例如 SignalR 应用程序)可以侦 StopListening 听事件,并在 IIS 启动应用程序池及其关联的辅助进程关闭时正常关闭其长时间运行的操作。

警告

实现事件时 StopListening ,开发人员必须考虑几个设计注意事项:

  1. 事件 StopListening 仅适用于配置为使用 IIS 集成管道的应用程序。
  2. 开发人员不得从其 StopListening 实现中引发错误;引发错误会产生不可预知的结果。
  3. 由于 ASP.NET 中操作的并发性质,无法保证 ASP.NET 在开发人员实现事件后会调用 StopListening 该事件。
  4. 事件 StopListening 可以与其他 IRegisteredObject 通知同时执行。
  5. 开发人员需要注意,ASP.NET 在执行事件时 StopListening 可能会关闭应用程序域,并设计其实现来处理这种可能性。
  6. StopListening 事件处理程序不得阻止;阻塞实现将导致死锁,当达到快速失败保护间隔时,IIS 将终止工作进程。

适用于