Cancel an async webrequest?
Asked Answered
F

1

7

I am using the Async CTP library for Windows Phone. Does anyone know how to cancel a pending webrequest?

Request = (HttpWebRequest)WebRequest.Create(url);
Request.Credentials = new NetworkCredential(_settings.Username, _settings.Password);
WebResponse resp;
try
{
    resp = await Request.GetResponseAsync();
}

There is no cancellation token (as specified in the ASYNC Ctp tap document).

Fine answered 26/12, 2011 at 12:21 Comment(0)
I
6

You could try calling Request.Abort().

Irma answered 26/12, 2011 at 15:46 Comment(2)
Thanx, it tried your solution. If I call the Request.Abort() the opperation still continues, and after a while the Async throws an exception. I tried with a fake address (which eventually gives a timeout) and then cancel the request.Fine
Seems to be the only solution. If I catch the WebException and check for the status, it gives me a RequestCancelled status. So this seems to be the way out! thnx.Fine

© 2022 - 2024 — McMap. All rights reserved.