private static void OnWriteUpgradeResponse(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult asyncState = (ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult) result.AsyncState;
         bool flag = false;
         Exception exception = null;
         try
         {
             flag = asyncState.HandleWriteUpgradeResponseComplete(result);
             if (flag)
             {
                 flag = asyncState.ContinueReading();
             }
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             exception = exception2;
             flag = true;
             asyncState.CleanupOnError();
             asyncState.channel.WriteAuditFailure(asyncState.channel.upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception2);
         }
         if (flag)
         {
             asyncState.Complete(false, exception);
         }
     }
 }
 private static void ReadCallback(object state)
 {
     ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult result = (ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult) state;
     bool flag = false;
     Exception exception = null;
     try
     {
         result.GetReadResult();
         flag = result.ContinueReading();
     }
     catch (Exception exception2)
     {
         if (Fx.IsFatal(exception2))
         {
             throw;
         }
         flag = true;
         exception = exception2;
         result.CleanupOnError();
     }
     if (flag)
     {
         result.Complete(false, exception);
     }
 }
 private static void OnWriteAckResponse(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult asyncState = (ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult) result.AsyncState;
         bool flag = false;
         Exception exception = null;
         try
         {
             flag = asyncState.HandleWriteAckComplete(result);
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             exception = exception2;
             flag = true;
             asyncState.CleanupOnError();
         }
         if (flag)
         {
             asyncState.Complete(false, exception);
         }
     }
 }