日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c# task

發布時間:2023/12/9 C# 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# task 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Task Parallel Library: 1 of n

http://www.codeproject.com/Articles/152765/Task-Parallel-Library-of-n

Task 與Thread, lambda,? action,funct之間有什么關聯。

Task相比Thread提供了什么方便之處。

Thread

1. 創建費時間,占用內存與CPU的資源

For example, when a new Thread is started in .NET, there is a whole process that goes with that, such as creating queues, thread local storage, managing the Thread's lifecycle etc. This takes time

ThreadPool

1. ThreadPool 免去了創建thread的時間,用戶直接將work item 委托給ThreadPool去安排其內部的線程調用。

2. 但classic threading ThreadPool,當一個work item已經在執行當中,用戶不能去直接關閉,想得到其的結果也是很直接。

However, even using the classic threading ThreadPool, there were problems in that you could not cancel a work item once it has been queued with the ThreadPool, or get a return result that easily. It just doesn't read that well either. There is an excellent article here on CodeProject that tackles some of these issues: Smart ThreadPool, which is pretty excellent actually. However, the new TPL infrastructure has got all these problems covered, and many many more useful features in my opinion.

Task

1. the new TPL infrastructure has got all these problems covered, and many many more useful features in my opinion

Task 繼承了ThreadPool的優點,解決了ThreadPool的問題。其本質也可以講Smart ThreadPool

2. A TPL Task actually uses the ThreadPool internally.

?

Task, ThreadPool, Thread, Scheduler

It is worth mentioning that Tasks are merely wrappers for passing a delegate of work to be done, also storing state, exceptions, and continuations amongst others. That work may or may not be done by the threadpool, and as already stated, that will depend upon the scheduler used.

?

常用的使用場景

Tasks also seem to be more inline with how people think about things. For instance, imagine this scenario: "I want to call a Web Service and have it return a List<int>". Using a TPL Task, I would create a Task<List<int>> and get it to call some service in its payload delegate (which will use the ThreadPool) that returned me a List<int>.

?

Task與UI Thread

reate/cancel Tasks and handle Exceptions

轉載于:https://www.cnblogs.com/pengxinglove/p/5452799.html

總結

以上是生活随笔為你收集整理的c# task的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。