Exemple #1
0
            private static void PostCallback(Object state)
            {
                Contract.Requires(state != null);
                Contract.Requires(((ApmWrapper)state).AsyncCallback != null);
                ApmWrapper apmWrap = (ApmWrapper)state;

                apmWrap.AsyncCallback(apmWrap);
            }
Exemple #2
0
        public T Unwrap(ref IAsyncResult result)
        {
            Contract.Requires(result != null);
            ApmWrapper apmWrap = (ApmWrapper)result;

            result = apmWrap.AsyncResult;
            return(apmWrap.Data);
        }
Exemple #3
0
            /// <summary>
            ///   Posts the callback.
            /// </summary>
            /// <param name="state">The object passed to the delegate.</param>
            private static void PostCallback(object state)
            {
                ApmWrapper apmWrap = (ApmWrapper)state;

                if (apmWrap != null)
                {
                    Debug.Assert(apmWrap.AsyncCallback != null);
                    apmWrap.AsyncCallback(apmWrap);
                }
            }
Exemple #4
0
        /// <summary>
        ///   Unwraps an ApmWrap object and also retrieves the embedded data.
        /// </summary>
        /// <param name="result">
        ///   The <see langword="ref">reference</see> to the wrapped IAsyncResult object.
        /// </param>
        /// <returns>The embedded data.</returns>
        public static T Unwrap([NotNull] ref IAsyncResult result)
        {
            ApmWrapper apmWrap = result as ApmWrapper;

            if (apmWrap == null)
            {
                throw new ArgumentException(Resources.ApmWrap_Unwrap_ResultWrongType, "result");
            }

            Debug.Assert(apmWrap.AsyncResult != null);
            result = apmWrap.AsyncResult;
            return(apmWrap.Data);
        }
Exemple #5
0
        public static AsyncCallback WrapCallback(
            [NotNull] AsyncCallback callback,
            T data,
            SynchronizationContext syncContext = null)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            ApmWrapper wrapper = new ApmWrapper
            {
                Data          = data,
                AsyncCallback = callback,
                SyncContext   = syncContext
            };

            return(wrapper.AsyncCallbackInternal);
        }