private void Complete(Exception exception, IAsyncResult result)
        {
            ContextAwareResult asyncState = (ContextAwareResult)result.AsyncState;

            try
            {
                if (this.cancelled)
                {
                    exception = null;
                    this.Abort();
                }
                else if ((exception != null) && (!(exception is SmtpFailedRecipientException) || ((SmtpFailedRecipientException)exception).fatal))
                {
                    this.Abort();
                    if (!(exception is SmtpException))
                    {
                        exception = new SmtpException(SR.GetString("SmtpSendMailFailure"), exception);
                    }
                }
                else
                {
                    if (this.writer != null)
                    {
                        this.writer.Close();
                    }
                    this.transport.ReleaseConnection();
                }
            }
            finally
            {
                asyncState.InvokeCallback(exception);
            }
        }
Exemplo n.º 2
0
        private void Complete(Exception exception, IAsyncResult result)
        {
            ContextAwareResult operationCompletedResult = (ContextAwareResult)result.AsyncState;

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this);
            }
            try
            {
                if (_cancelled)
                {
                    //any exceptions were probably caused by cancellation, clear it.
                    exception = null;
                    Abort();
                }
                // An individual failed recipient exception is benign, only abort here if ALL the recipients failed.
                else if (exception != null && (!(exception is SmtpFailedRecipientException) || ((SmtpFailedRecipientException)exception).fatal))
                {
                    if (NetEventSource.IsEnabled)
                    {
                        NetEventSource.Error(this, exception);
                    }
                    Abort();

                    if (!(exception is SmtpException))
                    {
                        exception = new SmtpException(SR.SmtpSendMailFailure, exception);
                    }
                }
                else
                {
                    if (_writer != null)
                    {
                        try
                        {
                            _writer.Close();
                        }
                        // Close may result in a DataStopCommand and the server may return error codes at this time.
                        catch (SmtpException se)
                        {
                            exception = se;
                        }
                    }
                    _transport.ReleaseConnection();
                }
            }
            finally
            {
                operationCompletedResult.InvokeCallback(exception);
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Info(this, "Complete");
            }
        }
        public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state)
        {
            ContextAwareResult asyncResult = new ContextAwareResult(false, false, this, state, callback);

            asyncResult.StartPostingAsyncOp(false);
            if (TeredoHelper.UnsafeNotifyStableUnicastIpAddressTable(StableUnicastAddressTableCallback, asyncResult))
            {
                asyncResult.InvokeCallback();
            }
            asyncResult.FinishPostingAsyncOp();

            return(asyncResult);
        }
        public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state)
        {
            if (!ComNetOS.IsVista)
            {
                throw new PlatformNotSupportedException(SR.GetString("VistaRequired"));
            }
            ContextAwareResult result = new ContextAwareResult(false, false, this, state, callback);

            result.StartPostingAsyncOp(false);
            if (TeredoHelper.UnsafeNotifyStableUnicastIpAddressTable(new Action <object>(SystemIPGlobalProperties.StableUnicastAddressTableCallback), result))
            {
                result.InvokeCallback();
            }
            result.FinishPostingAsyncOp();
            return(result);
        }
Exemplo n.º 5
0
        void Complete(Exception exception, IAsyncResult result)
        {
            ContextAwareResult operationCompletedResult = (ContextAwareResult)result.AsyncState;

            GlobalLog.Enter("SmtpClient#" + ValidationHelper.HashString(this) + "::Complete");
            try {
                if (cancelled)
                {
                    //any exceptions were probably caused by cancellation, clear it.
                    exception = null;
                    Abort();
                }
                // An individual failed recipient exception is benign, only abort here if ALL the recipients failed.
                else if (exception != null && (!(exception is SmtpFailedRecipientException) || ((SmtpFailedRecipientException)exception).fatal))
                {
                    GlobalLog.Print("SmtpClient#" + ValidationHelper.HashString(this) + "::Complete Exception: " + exception.ToString());
                    Abort();

                    if (!(exception is SmtpException))
                    {
                        exception = new SmtpException(SR.GetString(SR.SmtpSendMailFailure), exception);
                    }
                }
                else
                {
                    if (writer != null)
                    {
                        try {
                            writer.Close();
                        }
                        // Close may result in a DataStopCommand and the server may return error codes at this time.
                        catch (SmtpException se) {
                            exception = se;
                        }
                    }
                    transport.ReleaseConnection();
                }
            }
            finally {
                operationCompletedResult.InvokeCallback(exception);
            }
            GlobalLog.Leave("SmtpClient#" + ValidationHelper.HashString(this) + "::Complete");
        }
        public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state)
        {
            ContextAwareResult asyncResult = new ContextAwareResult(false, false, this, state, callback);
            asyncResult.StartPostingAsyncOp(false);
            if (TeredoHelper.UnsafeNotifyStableUnicastIpAddressTable(StableUnicastAddressTableCallback, asyncResult))
            {
                asyncResult.InvokeCallback();
            }

            asyncResult.FinishPostingAsyncOp();

            return asyncResult;
        }