By looping through multiple instances of TaskCompletionSource in the synchronous method, more than 5 programs will become slow to execute, but in the asynchronous method you don't have this problem.
This is problematic code Using the synchronization method, the execution becomes slow, creating one in about 1 second
Parallel.For(1, 100, (index) =>
{
System.Console.WriteLine("start:");
var t = new TaskCompletionSource<string>();
count++;
System.Console.WriteLine("end:" + count + "\n");
t.Task.Wait();
System.Console.WriteLine("ended:");
});
This is No problem code,Execute very fast
Parallel.For(1, 100, async (index) =>
{
System.Console.WriteLine("start:");
var t = new TaskCompletionSource<string>();
count++;
System.Console.WriteLine("end:" + count + "\n");
await t.Task;
System.Console.WriteLine("ended:");
});