public static void EndInvoke(IAsyncResult result, object owner)
        {
            AsyncResultNoResult ar = result as AsyncResultNoResult;

            if (ar == null)
            {
                throw new ArgumentException("Result passed represents an operation not supported " +
                                            "by this framework.");
            }

            ar.CheckUsage(owner);

            // This method assumes that only 1 thread calls EndInvoke for this object
            if (!ar.IsCompleted)
            {
                // If the operation isn't done, wait for it
                ar.AsyncWaitHandle.WaitOne();
                ar.AsyncWaitHandle.Close();
                ar.m_asyncWaitHandle = null; // Allow early GC
            }
            // Operation is done: if an exception occured, throw it
            if (ar.m_exception != null)
            {
                throw ar.m_exception;
            }
        }
 protected virtual void MakeCallback(AsyncCallback callback, AsyncResultNoResult result)
 {
     // If a callback method was set, call it
     if (callback != null)
     {
         callback(result);
     }
 }
        public new static TResult EndInvoke(IAsyncResult asyncResult, object owner)
        {
            AsyncResult <TResult> ar = asyncResult as AsyncResult <TResult>;

            if (ar == null)
            {
                throw new ArgumentException("Result passed represents an operation not supported " +
                                            "by this framework.");
            }
            AsyncResultNoResult.EndInvoke(asyncResult, owner);
            return(ar.m_result);
        }