Ejemplo n.º 1
0
 protected void Complete(bool completedSynchronously)
 {
     if (!this.isCompleted)
     {
         this.completedSynchronously = completedSynchronously;
         if (this.OnCompleting != null)
         {
             try
             {
                 this.OnCompleting(this, this.exception);
             }
             catch (Exception exception1)
             {
                 Exception exception = exception1;
                 if (!Fx.IsFatal(exception))
                 {
                     this.exception = exception;
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         if (!completedSynchronously)
         {
             lock (this.ThisLock)
             {
                 this.isCompleted = true;
                 if (this.manualResetEvent != null)
                 {
                     this.manualResetEvent.Set();
                 }
             }
         }
         else
         {
             this.isCompleted = true;
         }
         if (this.callback != null)
         {
             try
             {
                 if (this.VirtualCallback == null)
                 {
                     this.callback(this);
                 }
                 else
                 {
                     this.VirtualCallback(this.callback, this);
                 }
             }
             catch (Exception exception3)
             {
                 Exception exception2 = exception3;
                 if (!Fx.IsFatal(exception2))
                 {
                     throw Fx.Exception.AsError(new CallbackException(InternalSR.AsyncCallbackThrewException, exception2));
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         return;
     }
     else
     {
         throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.AsyncResultCompletedTwice(this.GetType())));
     }
 }
Ejemplo n.º 2
0
        protected void Complete(bool completedSynchronously)
        {
            if (_isCompleted)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.AsyncResultCompletedTwice));
            }



            _completedSynchronously = completedSynchronously;
            if (OnCompleting != null)
            {
                // Allow exception replacement, like a catch/throw pattern.
                try
                {
                    OnCompleting(this, _exception);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    _exception = exception;
                }
            }

            if (completedSynchronously)
            {
                // If we completedSynchronously, then there's no chance that the manualResetEvent was created so
                // we don't need to worry about a race condition.
                Fx.Assert(_manualResetEvent == null, "No ManualResetEvent should be created for a synchronous AsyncResult.");
                _isCompleted = true;
            }
            else
            {
                lock (ThisLock)
                {
                    _isCompleted = true;
                    if (_manualResetEvent != null)
                    {
                        _manualResetEvent.Set();
                    }
                }
            }

            if (_callback != null)
            {
                try
                {
                    if (VirtualCallback != null)
                    {
                        VirtualCallback(_callback, this);
                    }
                    else
                    {
                        _callback(this);
                    }
                }
#pragma warning disable 1634
#pragma warning suppress 56500 // transferring exception to another thread
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    throw Fx.Exception.AsError(new CallbackException(InternalSR.AsyncCallbackThrewException, e));
                }
#pragma warning restore 1634
            }
        }
Ejemplo n.º 3
0
 public FatalException(string message, Exception innerException) : base(message, innerException)
 {
     // This can't throw something like ArgumentException because that would be worse than
     // throwing the fatal exception that was requested.
     Fx.Assert(innerException == null || !Fx.IsFatal(innerException), "FatalException can't be used to wrap fatal exceptions.");
 }