public void EndInvoke()
{
// This method assumes that only 1 thread calls EndInvoke for this object
if (!IsCompleted)
{
// If the operation isn't done, wait for it
AsyncWaitHandle.WaitOne();
AsyncWaitHandle.Dispose();
_asyncWaitHandle = null; // Allow early GC
}
EndInvokeCalled = true;
// Operation is done: if an exception occurred, throw it
if (_exception != null)
throw _exception;
}