예제 #1
0
 public AsyncContext(Delegate @delegate, DelegateAsyncResult delegateAsyncResult, AsyncCallback asyncCallback, object userState)
 {
     AsyncDelegate       = @delegate;
     AsyncCallback       = asyncCallback;
     AsyncState          = userState;
     DelegateAsyncResult = delegateAsyncResult;
 }
예제 #2
0
        public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
        {
            GetResponseDelegate d           = new GetResponseDelegate(GetAsyncResponse);
            DelegateAsyncResult result      = new DelegateAsyncResult();
            AsyncContext        userContext = new AsyncContext(d, result, callback, state);

            result.AsyncResult = d.BeginInvoke(new AsyncCallback(DelegateAsyncResult.Callback), userContext);
            return(result);
        }
예제 #3
0
        public override WebResponse EndGetResponse(IAsyncResult asyncResult)
        {
            if (_isAborted)
            {
                throw new WebException("The operation has been aborted.", WebExceptionStatus.RequestCanceled);
            }
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            DelegateAsyncResult result = asyncResult as DelegateAsyncResult;

            if (result == null)
            {
                throw new ArgumentException("Invalid IAsyncResult", "asyncResult");
            }

            return(((GetResponseDelegate)result.AsyncDelegate).EndInvoke(result.AsyncResult));
        }