Are there any cases when it's preferable to use a plain old Thread object instead of one of the newer constructs?

前端 未结 10 1995
挽巷
挽巷 2021-01-30 01:45

I see a lot of people in blog posts and here on SO either avoiding or advising against the usage of the Thread class in recent versions of C# (and I mean of course

10条回答
  •  终归单人心
    2021-01-30 02:31

    The new options make direct use and management of the (expensive) threads less frequent.

    people that, when confronted with a task that involves some kind of parallel execution, jump directly to using the good old Thread class.

    Which is a very expensive and relatively complex way of doing stuff in parallel.

    Note that the expense matters most: You cannot use a full thread to do a small job, it would be counterproductive. The ThreadPool combats the costs, the Task class the complexities (exceptions, waiting and canceling).

提交回复
热议问题