Should I notice a difference in using Task vs Threads in .Net 4.0?

前端 未结 5 968
暖寄归人
暖寄归人 2021-02-05 08:59

I updated my code to use Tasks instead of threads....

Looking at memory usage and CPU I do not notices any improvements on the multi-core PC, Is this expected?

M

5条回答
  •  名媛妹妹
    2021-02-05 09:46

    If you simply replaced every usage of Thread with Task and did no other changes I would expect virtually the same performance. The Task API is really just that, it's an API over an existing set of constructs. Under the hood it uses threads to schedule it's activities and hence has similar performance characteristics.

    What's great about Task are the new things you can do with them

    • Composition with ContinueWith
    • Cancellation
    • Hierarchies
    • Etc ...

提交回复
热议问题