C# Async await和Task的关系
2016-03-09 23:07
981 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AsyncAwatiConsole { class Program { static void Main(string[] args) { Example(); string result = Console.ReadLine(); Console.WriteLine("You typed: " + result); } public static async void Example() { int t = await Task.Run(() => Allocate()); } public static void Example2() { Task<int> task = new Task<int>(() => { return 11; }); task.Start(); task.Wait(); } static int Allocate() { // Compute total count of digits in strings. int size = 0; for (int z = 0; z < 100; z++) { for (int i = 0; i < 1000000; i++) { string value = i.ToString(); if (value == null) { return 0; } size += value.Length; } } return size; } } }
相关文章推荐
- C# particle class
- C#参考书的链接推荐
- 关于C#中类方法的重写和覆盖
- C#中 As 和强制转换的总结
- (转)C# 使用BackgroundWorker
- 关于数组以及c#学习问题
- C#使用linq to xml完成对XML文件的创建、增加、删除、修改、查询
- C# 无参属性 set与get
- 继承和Protected修饰符(C#)
- C#旅途~登录框
- C#旅途之窗口化程序~百度
- 最后再给大家介绍一种最简单的C#跨窗体操作
- C# 委托和事件
- winform textBox输入提示
- C# 使用keybd_event()函数模拟键盘按键
- C# Winform应用程序占用内存较大解决方法整理
- c#模拟用户登录
- C#解leetcode 228. Summary Ranges Easy
- C# region的作用
- C#获得当前执行的函数名、当前代码行、源代码文件名