官术网_书友最值得收藏!

Generalized async return types

If you use async/await (if not, check it out) the following feature of C# 7.0 will come in really handy. The only supported return types used to be Task<T>, Task, and void. Even then, void was also only used with event handlers such as a button click. The challenge, however, was that a Task<T> was allocated in situations where the result of the async operation was available at the time of awaiting. But, what does this even mean? Well consider an async method that returns a Task<T> : and that value has a time to live of n amount of seconds. If the async method is called within the time to live period, why go to the trouble of allocating another Task<T> object? This is where the ValueTask<T> comes into play; it will allow other types to be defined so that you can return them from an async method. This, therefore, reduces the Task<T> allocations, which in turn will lead to performance gains.

主站蜘蛛池模板: 万安县| 甘孜| 平武县| 九江市| 安庆市| 克什克腾旗| 德安县| 北票市| 榆树市| 瑞昌市| 阳泉市| 黄龙县| 涟源市| 贵溪市| 文水县| 昂仁县| 长丰县| 尉犁县| 上蔡县| 偏关县| 雅安市| 杭锦旗| 孟州市| 施甸县| 含山县| 康马县| 抚远县| 香格里拉县| 长海县| 嘉禾县| 通海县| 兴宁市| 安平县| 平和县| 惠州市| 韶关市| 易门县| 德钦县| 弥渡县| 修文县| 平乡县|