c#异步task示例分享(异步操作)


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

    }
}


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3