CancellationTokenSource
seems to be ignoring the time for the loop operation. It takes a while to iterate over it and I have the limit set to 500ms but it's ignoring it. What could I be doing wrong?
static async Task<int> Thread1()
{
CancellationTokenSource source = new CancellationTokenSource();
source.CancelAfter(TimeSpan.FromMilliseconds(500));
return await Task.Run(async () =>
{
using (var client = new HttpClient())
{
var site = await client.GetAsync("http://webcode.me", source.Token);
for (int i = 0; i < 10000000; i++)
{
Console.WriteLine(i);
}
string content = await site.Content.ReadAsStringAsync();
return content.Count(x => x == 'e');
}
}, source.Token);
}