private static void PostCallback(Object state) { Contract.Requires(state != null); Contract.Requires(((ApmWrapper)state).AsyncCallback != null); ApmWrapper apmWrap = (ApmWrapper)state; apmWrap.AsyncCallback(apmWrap); }
public T Unwrap(ref IAsyncResult result) { Contract.Requires(result != null); ApmWrapper apmWrap = (ApmWrapper)result; result = apmWrap.AsyncResult; return(apmWrap.Data); }
/// <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); } }
/// <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); }
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); }