Exemple #1
0
        //[DebuggerStepThrough] // alanjmcf
        public void SetAsCompleted(Exception exception, AsyncResultCompletion completion)
        {
            bool completedSynchronously = completion == AsyncResultCompletion.IsSync;

            // Passing null for exception means no error occurred; this is the common case
            m_exception = exception;

            // The m_CompletedState field MUST be set prior calling the callback
            int prevState = Interlocked.Exchange(ref m_CompletedState,
                                                 completedSynchronously ? c_StateCompletedSynchronously : c_StateCompletedAsynchronously);

            if (prevState != c_StatePending)
            {
                throw new InvalidOperationException("You can set a result only once");
            }

            // If the event exists, set it
            if (m_AsyncWaitHandle != null)
            {
                m_AsyncWaitHandle.Set();
            }

            // If a callback method was set, call it
            if (m_AsyncCallback != null)
            {
                if (completion != AsyncResultCompletion.MakeAsync)
                {
                    m_AsyncCallback(this);
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(CallbackRunner);
                }
            }
        }
Exemple #2
0
        [DebuggerNonUserCode] // alanjmcf
        public void SetAsCompleted(TResult result, AsyncResultCompletion completion)
        {
            // Save the asynchronous operation's result
            m_result = result;

            // Tell the base class that the operation completed sucessfully (no exception)
            base.SetAsCompleted(null, completion);
        }
Exemple #3
0
        internal void SetAsCompletedWithResultOf(
            Func <TResult> getResultsOrThrow,
            AsyncResultCompletion completion)
        {
            TResult result;

            try {
                result = getResultsOrThrow();
            } catch (Exception ex) {
                this.SetAsCompleted(ex, completion);
                return;
            }
            this.SetAsCompleted(result, completion);
        }
Exemple #4
0
        //[DebuggerNonUserCode] // alanjmcf
        //[Obsolete("temp Call with: Boolean callbackOnNewThread")]
        public void SetAsCompleted(Exception exception, bool completedSynchronously)
        {
            AsyncResultCompletion x = ConvertCompletion(completedSynchronously);

            SetAsCompleted(exception, x);
        }