My goal is to give the thread executing the task a name e.g. "WorkerForXY". But I don't want to name the thread inside of the task.
What is working but I don't want:
Task.Factory.StartNew(() =>
{
Thread.CurrentThread.Name = $"WorkerFor{taskName}";
// some code
}, TaskCreationOptions.LongRunning);
What I want to do:
var task = Task.Factory.StartNew(() =>
{
// some code
}, TaskCreationOptions.LongRunning);
task.GetAssignedWorkerThreadIfAvailable().Name = $"WorkerFor{taskName}"; // or something similar
I think there might be a solution because Visual Studio can create such a mapping: