I have an application that runs without problems for a long time, which unexpectedly does not start due to the following error:
"This property is already set and cannot be changed."
When I check the code, which basically looks like the snippet below, I see that the exception is thrown on the line that is trying to name the first task inside Parallel.Invoke
Thread.CurrentThread.Name = "Main Program Thread";
// Do some start up tasks in parallel
Parallel.Invoke(new ParallelOptions { MaxDegreeOfParallelism = 10 },
() =>
{
Thread.CurrentThread.Name = "First thread";
},
() =>
{
Thread.CurrentThread.Name = "Second thread";
});
...
Obviously, the reason for this should be that the main thread already has a name, and the first task is performed in the main thread, and not in the thread thread.
, Parallel.Invoke, , . , Parallel.Invoke() threadpool - ? ?
, , - . , .