Ejemplo n.º 1
0
        internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback?callback, object?state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(conn, callback, state);

            multiResult.Enter();
            IAsyncResult writeResult = conn.BeginFlush(s_onWrite, multiResult);

            if (writeResult.CompletedSynchronously)
            {
                conn.EndFlush(writeResult);
                multiResult.Leave();
            }
            SmtpReplyReader reader = conn.Reader !.GetNextReplyReader();

            multiResult.Enter();
            IAsyncResult readLinesResult = reader.BeginReadLines(s_onReadLines, multiResult);

            if (readLinesResult.CompletedSynchronously)
            {
                LineInfo[] lines = SmtpReplyReader.EndReadLines(readLinesResult);
                if (!(multiResult.Result is Exception))
                {
                    multiResult.Result = lines;
                }
                multiResult.Leave();
            }
            multiResult.CompleteSequence();
            return(multiResult);
        }
Ejemplo n.º 2
0
 private static void OnReadLines(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState !;
         try
         {
             SmtpConnection conn  = (SmtpConnection)multiResult.Context;
             LineInfo[]     lines = SmtpReplyReader.EndReadLines(result);
             if (!(multiResult.Result is Exception))
             {
                 multiResult.Result = lines;
             }
             multiResult.Leave();
         }
         catch (Exception e)
         {
             multiResult.Leave(e);
         }
     }
 }