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