How can I assign a name to a task in TPL

后端 未结 11 1275
礼貌的吻别
礼貌的吻别 2021-02-12 10:24

I\'m going to use lots of tasks running on my application. Each bunch of tasks is running for some reason. I would like to name these tasks so when I watch the Parallel Tasks wi

11条回答
  •  忘了有多久
    2021-02-12 11:25

    You can't really name a Task, but you can name the method which is executed by a Task, which is then shown in the Parallel Tasks windows. So, if naming the Tasks is important for you, don't use lambdas, use normal named methods.

    Surprisingly, this works even with Parallel, even though there the Task isn't executing your method directly. I think this is because Parallel Tasks somehow knows about Tasks from Parallel and handles them differently.

提交回复
热议问题