Parallel.For<string>(0, 20, () =>
{
// invoked once for each thread
Console.WriteLine("init thread {0}, task {1}", Thread.CurrentThread.ManagedThreadId, Task.CurrentId);
return String.Format("t{0}",
Thread.CurrentThread.ManagedThreadId);
}, (i, pls, str1) =>
{
// invoked for each member
Console.WriteLine("body i {0} str1 {1} thread {2} task {3}", i, str1,
Thread.CurrentThread.ManagedThreadId, Task.CurrentId);
Thread.Sleep(10);
return String.Format("i {0}", i);
}, (str1) =>
{
// final action on each thread
Console.WriteLine("finally {0}", str1);
});
I got these code from the book 《Professional C# 5.0 and .NET 4.5.1》, and the book shows the result at page 560 :
I think the result where I around it with red retangle may be wrong, It should be "body i 1 str1 t1 thread 1 task 1", Is that I comprehend these right? or I was wrong about that. Is there anyone can explain these to me ? thanks