HostingEnvironment.StopListening Event


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

[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.

Namespace:   System.Web.Hosting
Assembly:  System.Web (in System.Web.dll)

public static event EventHandler StopListening

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. 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.


There are several design considerations that a developer must consider when implementing the StopListening event:

  1. The StopListening event is only available for applications that are configured to use the IIS integrated pipeline.

  2. Developers must not throw errors from their StopListening implementations; throwing errors will have unpredictable results.

  3. 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.

  4. The StopListening event can execute concurrently with other IRegisteredObject notifications.

  5. 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.

  6. 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.

.NET Framework
Available since 4.5.1
Return to top