c#异步task示例分享(异步操作)
发布时间:2016-12-28 来源:查字典编辑
摘要:c#Task异步操作复制代码代码如下:usingSystem;usingSystem.Threading;usingSystem.Threa...
c# Task异步操作
复制代码 代码如下:
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
Func<string, string> _processTimeFunc = new Func<string, string>((string arg) =>
{
return string.Format("{0} {1}", arg, DateTime.Now);
});
Task.Factory.FromAsync<string, string>(_processTimeFunc.BeginInvoke, _processTimeFunc.EndInvoke, "Zhuzhou", null)
.ContinueWith((result) =>
{
Console.WriteLine(result.Result);
});
Console.ReadLine();
}
}
}