Task<TResult>的使用

https://msdn.microsoft.com/en-us/library/dd321424(v=vs.110).aspx

Represents an asynchronous operation that can return a value.

Type Parameters

TResult

The type of the result produced by this Task<TResult>.

 

 

Task<TResult>.Result 属性

Gets the result value of this Task<TResult>.

public TResult Result { get; }

The result value of this Task<TResult>, which is the same type as the task's type parameter.

 

Accessing the property's get accessor blocks the calling thread until the asynchronous operation is complete; it is equivalent to calling the Wait method.

尝试获取Result会阻塞调用线程,直到异步操作完成。这等价于调用Wait方法。

Once the result of an operation is available, it is stored and is returned immediately on subsequent calls to the Result property.

Note that, if an exception occurred during the operation of the task, or if the task has been cancelled, the Result property does not return a value.

Instead, attempting to access the property value throws an AggregateException exception.

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(1033)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2014-07-18 C#创建继承的窗体
2014-07-18 git的软件安装
点击右上角即可分享
微信分享提示