http client cancel request in windows 8.1

て烟熏妆下的殇ゞ 提交于 2019-12-02 22:54:22

Haven't tested it yet, but this could work:

await client.GetStringAsync(new Uri("http://www.google.com")).AsTask(cancellationToken);

If you don't have the need for cancellation tokens, you can also cancel the IAsyncOperation directly like this:

var operation = _httpClient.GetStringAsync(new Uri("http://www.google.com"));
var response = await operation;

operation.Cancel();

This blog post is a good read on the whole Task vs IAsyncOperation topic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!