I an creating a sample example to call link using WebClient using async and await method now I want to attach cancel async call functionality also. But I am not able to get Can
Extension methods based on svick's answer:
public static async Task DownloadStringTaskAsync(this WebClient webClient, string url, CancellationToken cancellationToken) {
using (cancellationToken.Register(webClient.CancelAsync)) {
return await webClient.DownloadStringTaskAsync(url);
}
}
public static async Task DownloadStringTaskAsync(this WebClient webClient, Uri uri, CancellationToken cancellationToken) {
using (cancellationToken.Register(webClient.CancelAsync)) {
return await webClient.DownloadStringTaskAsync(uri);
}
}