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

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.

主站蜘蛛池模板: 平安县| 五台县| 阳城县| 沧州市| 永善县| 韶山市| 虹口区| 青阳县| 天峨县| 汉中市| 贵阳市| 论坛| 图们市| 中江县| 方山县| 永嘉县| 富蕴县| 泰和县| 应城市| 临沂市| 六枝特区| 五华县| 岳阳县| 永修县| 武义县| 准格尔旗| 边坝县| 金秀| 济源市| 汕头市| 兴业县| 荣成市| 隆子县| 沿河| 汉中市| 科技| 湟源县| 元江| 长子县| 翁牛特旗| 皋兰县|