您的位置:首页 > 编程语言 > C#

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;
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: