码迷,mamicode.com
首页 > Windows程序 > 详细

c# 异步方法

时间:2018-09-18 17:11:47      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:task   调用   异步   value   str   wait   string   arp   方法   

1.异步方法的定义

        public string GetValue()
        {
            return "value";
        }
        public async Task<string> GetValueAsync()
        {
            string t = await Task.Run(() => GetValue());
            return t;
        }

2.异步方法的调用

            Task<string> t = GetValueAsync();
            string value = await t;

  

c# 异步方法

标签:task   调用   异步   value   str   wait   string   arp   方法   

原文地址:https://www.cnblogs.com/by-lhc/p/9669699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!