HostingEnvironment.StopListening 事件
定义
[仅在 .NET Framework 4.5.1 中受支持][Supported in the .NET Framework 4.5.1 only]
当辅助进程或与该主机相关联的应用程序池已停止侦听新的请求,并将最终关闭时才发生。Occurs when the worker process or application pool associated with this host has stopped listening for new requests and will eventually shut down.
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 运行时应用程序正在关闭,并且应用程序池的辅助进程将停止侦听新的请求。When an application pool and its associated worker processes are being shut down by IIS, for example when an application pool has reached a scheduled recycle interval, IIS notifies the ASP.NET runtime that the application is shutting down and the worker process for the application pool stops listening for new requests. 如果应用程序使用长时间运行的请求(例如 SignalR 应用程序),则可以侦听 StopListening 事件,并在 IIS 启动应用程序池及其关联的工作进程的关闭时正常关闭其长时间运行的操作。Applications that use long-running requests, for example SignalR applications, can listen for the StopListening event and gracefully shut down their long-running operations when IIS has initiated the shutdown of an application pool and its associated worker processes.
警告
开发人员在实现事件时必须考虑几个设计注意事项 StopListening :There are several design considerations that a developer must consider when implementing the StopListening event:
- 此 StopListening 事件仅适用于配置为使用 IIS 集成管道的应用程序。The StopListening event is only available for applications that are configured to use the IIS integrated pipeline.
- 开发人员不得从其实现中引发错误 StopListening ; 引发错误将产生不可预知的结果。Developers must not throw errors from their StopListening implementations; throwing errors will have unpredictable results.
- 由于 ASP.NET 中的操作的并发性质,因此,在开发人员实现某个事件后,就不能保证 ASP.NET 会调用 StopListening 它。Due to the concurrent nature of operations within ASP.NET, there is no guarantee that ASP.NET will call a StopListening event once it has been implemented by a developer.
- StopListening事件可与其他通知并发执行 IRegisteredObject 。The StopListening event can execute concurrently with other IRegisteredObject notifications.
- 开发人员需要注意,ASP.NET 可以在其事件执行时关闭应用程序域 StopListening ,并设计其实现来处理这种可能性。Developers need to be aware that ASP.NET may shut down the application domain while their StopListening event is executing and design their implementations to handle that possibility.
- StopListening 事件处理程序不能阻止;阻塞实现将导致死锁,并且在达到快速失败保护时间间隔时,IIS 将终止工作进程。StopListening event handlers must not block; blocking implementations will result in deadlocks, and IIS will terminate the worker process when the rapid fail protection interval is reached.