using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks; namespace ConAppAsync
{
class Program
{ //第一步,创建一个普通的耗时的方法
static string Greeting(string name)
{
Thread.Sleep();
return String.Format("Hello, {0}", name);
} //第二步,用一个异步方法包装上面的方法
static Task<string> GreetingAsync(string name)
{
return Task.Run<string>(() =>
{
return Greeting(name);
});
} //第三步,再创建一个能调用上面的异步方法的方法, 加关键字 async private async static void CallWithAsync()
{
//some other tasks string result = await GreetingAsync("王海滨"); //we can add multiple "await" in same "async" method
string result1 = await GreetingAsync("Ahmed");
string result2 = await GreetingAsync("Every Body");
Console.WriteLine(result+result1+result2);
} static void Main(string[] args)
{
//最后在主入口调用上面的方法,和调用普通方法一样
CallWithAsync();
int length = ;
for (int i = ; i < length; i++)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
}
}

最新文章

  1. 解决eclipse配置Tomcat时找不到server选项(Mac通用)
  2. SVN里常见的图标及其含义
  3. ZOJ 3865 Superbot(优先队列--模板)
  4. Buy Tickets(线段树)
  5. java学习第七天
  6. POJ -3050 Hopscotch
  7. ARC代码和非ARC代码 混用
  8. 《白手起家Win32SDK应用程序》(完整版+目录)
  9. 在uboot里面加入环境变量使用run来运行
  10. CentOS6.8使用源码安装Git
  11. Hibernate配置文件的hbm2ddl.auto属性
  12. node将excel内容转json
  13. ASP.NET Core 源码学习之 Logging[1]:Introduction
  14. codeforces gym 101611C 重链剖分构造
  15. python functools
  16. MVC Log4Net 配置
  17. 异常与Final
  18. Ubuntu界面重新安装图形界面
  19. java itext 报错 com.itextpdf.text.DocumentException: Font &#39;STSong-Light&#39; with &#39;UniGB-UCS2-H&#39;
  20. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B. Code obfuscation 水题

热门文章

  1. html部分常用标签的含义及作用
  2. POJ1064--Cable master(Binary Search)
  3. http基本概念
  4. hihocoder 二分·二分答案【二分搜索,最大化最小值】 (bfs)
  5. java基础知识-算术运算符和赋值运算符
  6. Linux下SVN配置hook经验总结
  7. [转载]腾讯专家:论高级DBA的自我修养
  8. 曲苑杂坛--DML操作中如何处理那些未提交的数据
  9. (zxing.net)二维码Aztec的简介、实现与解码
  10. 剑指offer编程题Java实现——面试题7相关题用两个队列实现一个栈