How to get the reference of TPL task's thread in C#?

后端 未结 3 1945
無奈伤痛
無奈伤痛 2021-01-13 05:25

When I create a task as

Task task = Task.Factory.StartNew(() => someMethod(args));

in C# 4.0+, how can I get the reference of the thr

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 06:14

    You can use:

    System.Threading.Thread.CurrentThread
    

    But as said in the comments, you use the TPL to abstract threading away, so going back to this "low level" is a likely indicator of poor design.

提交回复
热议问题