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

前端 未结 10 2115
挽巷
挽巷 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:32

    The Thread class cannot be made obsolete because obviously it is an implementation detail of all those other patterns you mention.

    But that's not really your question; your question is

    are there any cases when it's necessary or useful to use a plain old Thread object instead of one of the above constructs?

    Sure. In precisely those cases where one of the higher-level constructs does not meet your needs.

    My advice is that if you find yourself in a situation where existing higher-abstraction tools do not meet your needs, and you wish to implement a solution using threads, then you should identify the missing abstraction that you really need, and then implement that abstraction using threads, and then use the abstraction.

提交回复
热议问题