private void ListenerAdapter_ApplicationPoolCanOpenNewListenerChannelInstance(object sender, ApplicationPoolListenerChannelInstanceEventArgs e)
 {
     EnqueueApplicationAction(apps =>
     {
         var app = apps.Values
         .Where(a => a.ApplicationPoolName == e.ApplicationPoolId)
         .Where(a => a.ListenerChannelId.GetValueIfCreatedOrDefault() == e.ListenerChannelId)
         .FirstOrDefault();
         if (app != null)
         {
             app.CanOpenNewListenerChannelInstance = true;
             OpenNewListenerChannelInstance(app, NewListenerChannelInstanceConstraints.HasPendingMessages);
         }
     });
 }
 private void ListenerAdapter_ApplicationPoolListenerChannelInstancesStopped(object sender, ApplicationPoolListenerChannelInstanceEventArgs e)
 {
     EnqueueApplicationAction(apps =>
     {
         var app = apps.Values
         .Where(a => a.ListenerChannelId.GetValueIfCreatedOrDefault() == e.ListenerChannelId)
         .Where(a => a.ApplicationPoolName == e.ApplicationPoolId)
         .FirstOrDefault();
         if (app != null)
         {
             TraceInformation($"Stopping application [{app.ApplicationKey}:{app.ApplicationPath}].", GetType());
             app.RequestsBlockedState = ApplicationRequestsBlockedStates.Blocked;
         }
     });
 }