Open
Description
openedon Jun 13, 2024
Description
In the tasks, for some reason, the status shows that they have already been completed, but they are still running. Because of this, Task.WaitAll does not stop them, as it thinks they have already finished. This is a strange behavior.
Reproduction Steps
using System;
using System.Collections.Concurrent;
var response = Enumerable.Range(0, 1000);
var res = response.Chunk(100);
var ls = new List<Task>();
CancellationTokenSource factory = new();
ConcurrentBag<string> info = new ConcurrentBag<string>();
foreach (var element in res)
{
var task = new Task(async () =>
{
await Task.Delay(1000000, factory.Token)
.ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
foreach (var item in element)
{
info.Add(item.ToString());
Console.Write(item + "|");
}
}, TaskCreationOptions.LongRunning);
ls.Add(task);
task.Start();
}
await Task.Delay(3000);
factory.Cancel();
Task.WaitAll(ls.ToArray());
Console.WriteLine($"Counts Distinct Items:{info.Distinct().Count()} Count {info.Count}");
Console.ReadKey();
Expected behavior
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment