If I have the following program
public class MainClass {
public static void Main () {
Console.WriteLine($"Main [{Thread.CurrentThread.ManagedThreadId}]");
Parallel.Invoke(
() => Foo(),
() => Bar()
);
Console.WriteLine("Done");
}
static void Foo() {
Console.WriteLine($"Foo[{Thread.CurrentThread.ManagedThreadId}]");
}
static void Bar() {
Console.WriteLine($"Bar[{Thread.CurrentThread.ManagedThreadId}]");
}
}
then under .net core 3.1 will it produce output like
Main [1]
Foo[1]
Bar[4]
Done
My question now is it guaranteed that Parallel.Invoke()
will use it's calling thread to do some or all the work that it is given? Like will this be on every platform or framework or does it behave differently on some UI Frameworks like WPF or WinForms.
My question also is not whether it will block the calling thread or not but whether the calling thread will do some of the work.
For example could the output of the above code be
Main [1]
Foo[2]
Bar[3]
Done