当前位置:网站首页>Asynctask < T> decoration and await are not used in synchronous methods to obtain asynchronous return values (asynchronous methods are called in synchronous methods)
Asynctask < T> decoration and await are not used in synchronous methods to obtain asynchronous return values (asynchronous methods are called in synchronous methods)
2022-07-26 10:33:00 【Miners learn programming】
In development , Our common asynchronous call is to add async Task<T> , Specific calls are used on asynchronous methods var value = await funtion(), To get the value .
It is often written like this .
public async Task<IActionResult> Index()
{
var client = new HttpClient(new HttpClientHandler
{
CookieContainer = new CookieContainer(),
UseCookies = true
});
var str = await client.GetStringAsync("youUrl");
return Content(str);
}But sometimes , Method Index Methods can only be synchronized , How should I call it ? It's very simple , Just add .Result That's all right. .
public IActionResult Index()
{
var client = new HttpClient(new HttpClientHandler
{
CookieContainer = new CookieContainer(),
UseCookies = true
});
var str = client.GetStringAsync("youUrl").Result;
return Content(str);
} Call asynchronous method in synchronous method ( No return value ) reference :C# Call asynchronous method in synchronous method This blog
static void Main(string[] args)
{
TestAsync().Wait();
}
边栏推荐
- 我们的Web3创业项目,黄了
- Agenda express | list of sub forum agenda on July 27
- 【Halcon视觉】图像滤波
- 10 令 operator= 返回一个 reference to *this
- Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
- Tradingview 使用教程
- Interview questions and answers of the first company (I)
- Mlx90640 infrared thermal imager temperature sensor module development notes (6)
- [Halcon vision] software programming ideas
- 上传图片获取宽高
猜你喜欢

vscode上使用anaconda(已经配置好环境)

抓包工具fiddler和wireshark对比

我们的Web3创业项目,黄了

【论文下饭】Deep Mining External Imperfect Data for ChestX-ray Disease Screening
![[Halcon vision] array](/img/29/905d93795a24538fded18d2d377e52.png)
[Halcon vision] array

数据分析入门 | kaggle泰坦尼克任务(一)—>数据加载和初步观察

videojs转canvas暂停、播放、切换视频

Deduct daily question 838 of a certain day

Okaleido生态核心权益OKA,尽在聚变Mining模式

【Halcon视觉】形态学腐蚀
随机推荐
少了个分号
上传图片获取宽高
[leetcode每日一题2021/8/30]528. 按权重随机选择【中等】
What if MySQL can't get in
MLX90640 红外热成像仪测温传感器模块开发笔记(六)红外图像伪彩色编码
面试第二家公司的面试题及答案(二)
Interview questions and answers for the second company (2)
QRcode二维码(C语言)遇到的问题
Redis特殊数据类型使用场景
Dynamically determine file types through links
[Halcon vision] threshold segmentation
2022/07/25 ------ arrangement of strings
单元测试,到底什么是单元测试,为什么单测这么难写
[C language] LINQ overview
【Halcon视觉】阈值分割
Closure of go (cumulative sum)
12 复制对象时勿忘其每一个成分
Li Kou daily question 917
链式方法调用的事务问题剖析
Review of database -- 1. Overview