walter
walter

Reputation: 823

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

From MSDN:

"The Abort 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?

Upvotes: 2

Views: 631

Answers (1)

walter
walter

Reputation: 823

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..........

Upvotes: 1

Related Questions