开发者

Does calling Abort on HttpWebRequest has any affect on responseStream.BeginRead

开发者 https://www.devze.com 2023-03-23 11:09 出处:网络
From MSDN: \"The Ab开发者_开发技巧ort method cancels a request to a resource. After a request is

From MSDN:

"The Ab开发者_开发技巧ort method cancels a request to a resource. After a request is canceled, calling the GetResponse, BeginGetResponse, EndGetResponse, GetRequestStream, BeginGetRequestStream, or EndGetRequestStream method causes a WebException with the Status property set to RequestCanceled."

But if responseStream.BeginRead is in progress, does Abort cancel this read?


Yes, it is affecting reading from a stream. I have tested sample code that was used in msdn HttpWebRequest.Abort Method, and call to EndRead was throwing an exception in ReadCallBack function.

RequestState myRequestState = (RequestState)asyncResult.AsyncState;
Stream responseStream = myRequestState.streamResponse;
int read = responseStream.EndRead(asyncResult);

ReadCallBack Exception raised!

Message:The request was aborted: The request was canceled.

Status:RequestCanceled Press any key to continue..........

0

精彩评论

暂无评论...
验证码 换一张
取 消