-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed as not planned
Labels
area-System.Threading.TasksquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
area-System.Threading.TasksquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.