internal void EnqueueAndStartProcessingThread(
     RemoteDataObject <PSObject> remoteObject,
     PSRemotingTransportException transportException,
     object privateData)
 {
     if (this.isClosed)
     {
         return;
     }
     lock (this.callbackNotificationQueue)
     {
         if (remoteObject != null || transportException != null || privateData != null)
         {
             BaseClientTransportManager.ReceivedDataInformation receivedDataInformation = new BaseClientTransportManager.ReceivedDataInformation();
             receivedDataInformation.remoteObject       = remoteObject;
             receivedDataInformation.transportException = transportException;
             receivedDataInformation.privateData        = privateData;
             if (remoteObject != null && (remoteObject.DataType == RemotingDataType.PublicKey || remoteObject.DataType == RemotingDataType.EncryptedSessionKey || remoteObject.DataType == RemotingDataType.PublicKeyRequest))
             {
                 this.CryptoHelper.Session.BaseSessionDataStructureHandler.RaiseKeyExchangeMessageReceived(remoteObject);
             }
             else
             {
                 this.callbackNotificationQueue.Enqueue(receivedDataInformation);
             }
         }
         if (this.isServicingCallbacks || this.callbackNotificationQueue.Count <= 0)
         {
             return;
         }
         this.isServicingCallbacks = true;
         ThreadPool.QueueUserWorkItem(new WaitCallback(this.ServicePendingCallbacks));
     }
 }
 internal void ServicePendingCallbacks(object objectToProcess)
 {
     BaseClientTransportManager.tracer.WriteLine("ServicePendingCallbacks thread is starting", new object[0]);
     BaseTransportManager.ETWTracer.ReplaceActivityIdForCurrentThread(this.runspacePoolInstanceId, PSEventId.OperationalTransferEventRunspacePool, PSEventId.AnalyticTransferEventRunspacePool, PSKeyword.Transport, PSTask.None);
     try
     {
         while (!this.isClosed)
         {
             BaseClientTransportManager.ReceivedDataInformation receivedDataInformation = (BaseClientTransportManager.ReceivedDataInformation)null;
             lock (this.callbackNotificationQueue)
             {
                 if (this.callbackNotificationQueue.Count <= 0)
                 {
                     break;
                 }
                 receivedDataInformation = this.callbackNotificationQueue.Dequeue();
             }
             if (receivedDataInformation != null)
             {
                 if (receivedDataInformation.transportException != null)
                 {
                     this.RaiseErrorHandler(new TransportErrorOccuredEventArgs(receivedDataInformation.transportException, TransportMethodEnum.ReceiveShellOutputEx));
                     break;
                 }
                 if (receivedDataInformation.privateData != null)
                 {
                     this.ProcessPrivateData(receivedDataInformation.privateData);
                 }
                 else
                 {
                     this.OnDataAvailableCallback(receivedDataInformation.remoteObject);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         CommandProcessorBase.CheckForSevereException(ex);
         BaseClientTransportManager.tracer.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Exception processing data. {0}", (object)ex.Message), new object[0]);
         this.RaiseErrorHandler(new TransportErrorOccuredEventArgs(new PSRemotingTransportException(ex.Message), TransportMethodEnum.ReceiveShellOutputEx));
     }
     finally
     {
         lock (this.callbackNotificationQueue)
         {
             BaseClientTransportManager.tracer.WriteLine("ServicePendingCallbacks thread is exiting", new object[0]);
             this.isServicingCallbacks = false;
             this.EnqueueAndStartProcessingThread((RemoteDataObject <PSObject>)null, (PSRemotingTransportException)null, (object)null);
         }
     }
 }