Beispiel #1
0
 /// <summary>Begins an asynchronous request for a file system resource.</summary>
 /// <returns>An <see cref="T:System.IAsyncResult" /> that references the asynchronous request.</returns>
 /// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate. </param>
 /// <param name="state">An object that contains state information for this request. </param>
 /// <exception cref="T:System.InvalidOperationException">The stream is already in use by a previous call to <see cref="M:System.Net.FileWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)" />. </exception>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 /// </PermissionSet>
 public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
 {
     lock (this)
     {
         if (this.asyncResponding)
         {
             throw new InvalidOperationException("Cannot re-call start of asynchronous method while a previous call is still in progress.");
         }
         this.asyncResponding = true;
     }
     FileWebRequest.GetResponseCallback getResponseCallback = new FileWebRequest.GetResponseCallback(this.GetResponseInternal);
     return(getResponseCallback.BeginInvoke(callback, state));
 }
Beispiel #2
0
        /// <summary>Ends an asynchronous request for a file system resource.</summary>
        /// <returns>A <see cref="T:System.Net.WebResponse" /> that contains the response from the file system resource.</returns>
        /// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> that references the pending request for a response. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="asyncResult" /> is null. </exception>
        public override WebResponse EndGetResponse(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            if (!asyncResult.IsCompleted)
            {
                asyncResult.AsyncWaitHandle.WaitOne();
            }
            AsyncResult asyncResult2 = (AsyncResult)asyncResult;

            FileWebRequest.GetResponseCallback getResponseCallback = (FileWebRequest.GetResponseCallback)asyncResult2.AsyncDelegate;
            WebResponse result = getResponseCallback.EndInvoke(asyncResult);

            this.asyncResponding = false;
            return(result);
        }