public override void StopListenerChannel(int listenerChannelId, bool immediate)
        {
            Debug.Print("BaseProcessProtocolHandler.StopListenerChannel(protocolId:" + protocolId + ", listenerChannelId:" + listenerChannelId + ", immediate:" + immediate + ")");
            ListenerChannelContext listenerChannelContext = this.listenerChannelIdMapping[listenerChannelId];

            adphManager.StopAppDomainProtocolListenerChannel(listenerChannelContext.AppKey, protocolId, listenerChannelId, immediate);

            lock (this.listenerChannelIdMapping)
            {
                // Remove the channel id.
                this.listenerChannelIdMapping.Remove(listenerChannelId);
            }
        }
        // Start per-process listening for messages
        public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback)
        {
            Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel()");
            if (listenerChannelCallback == null)
            {
                DiagnosticUtility.DebugAssert("listenerChannelCallback is null");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false);
            }

            this.listenerChannelCallback = listenerChannelCallback;

            int listenerChannelDataLength = listenerChannelCallback.GetBlobLength();

            byte[] listenerChannelData = new byte[listenerChannelDataLength];
            listenerChannelCallback.GetBlob(listenerChannelData, ref listenerChannelDataLength);
            Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() GetBlob() contains " + listenerChannelDataLength + " bytes");

            listenerChannelContext = ListenerChannelContext.Hydrate(listenerChannelData);

            Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() calling OnStart()");
#if DEBUG
            // Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() waiting for you to attach the debugger to " + Process.GetCurrentProcess().ProcessName + " Pid: " + Process.GetCurrentProcess().Id);
            // for (int sleepCount = 0; sleepCount < 30 && !Debugger.IsAttached && !ListenerUnsafeNativeMethods.IsDebuggerPresent(); sleepCount++) { Thread.Sleep(500); } Debugger.Break();
#endif
            try
            {
                OnStart();

                listenerChannelCallback.ReportStarted();
                Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() called ReportStarted()");
            }
            catch (CommunicationException exception)
            {
                Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() failed in OnStart():\r\n" + exception);
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.WebHost,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.WebHostFailedToListen,
                                                    listenerChannelContext.AppKey,
                                                    this.protocolId,
                                                    TraceUtility.CreateSourceString(this),
                                                    exception.ToString());

                throw;
            }
        }
        // Start per-process listening for messages
        public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback, IAdphManager adphManager)
        {
            DiagnosticUtility.DebugAssert(listenerChannelCallback != null, "The listenerChannelCallback parameter must not be null");
            DiagnosticUtility.DebugAssert(adphManager != null, "The adphManager parameter must not be null");

            int channelId = listenerChannelCallback.GetId();
            ListenerChannelContext listenerChannelContext;

            lock (this.listenerChannelIdMapping)
            {
                if (!listenerChannelIdMapping.TryGetValue(channelId, out listenerChannelContext))
                {
                    int    listenerChannelDataLength = listenerChannelCallback.GetBlobLength();
                    byte[] listenerChannelData       = new byte[listenerChannelDataLength];
                    listenerChannelCallback.GetBlob(listenerChannelData, ref listenerChannelDataLength);
                    Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() GetBlob() contains " + listenerChannelDataLength + " bytes");
                    listenerChannelContext = ListenerChannelContext.Hydrate(listenerChannelData);
                    this.listenerChannelIdMapping.Add(channelId, listenerChannelContext);
                    Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() listenerChannelContext.ListenerChannelId: " + listenerChannelContext.ListenerChannelId);
                }
            }

            if (this.adphManager == null)
            {
                this.adphManager = adphManager;
            }

            try
            {
                // wether or not a previous AppDomain was running, we're going to start a new one now:
                Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() calling StartAppDomainProtocolListenerChannel(appKey:" + listenerChannelContext.AppKey + " protocolId:" + protocolId + ")");
                adphManager.StartAppDomainProtocolListenerChannel(listenerChannelContext.AppKey, protocolId, listenerChannelCallback);
            }
            catch (Exception ex)
            {
                if (Fx.IsFatal(ex))
                {
                    throw;
                }

                DiagnosticUtility.TraceHandledException(ex, TraceEventType.Error);

                HandleStartListenerChannelError(listenerChannelCallback, ex);
            }
        }