码迷,mamicode.com
首页 > 编程语言 > 详细

Task示例,多线程

时间:2014-10-28 13:33:37      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:blog   ar   div   on   art   log   line   new   as   

 class Program
    {
        static void Main(string[] args)
        {
            Run();
          
        }

        public static async void Run()
        {
            var tasks = StartMultiWorkerTasks();
            if (tasks.Length > 0)
            {
                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    Console.WriteLine("done ......");
                });
            }
            Task.WaitAll(tasks);
        }


        /// <summary>
        /// Start multi tasks
        /// </summary>
        /// <param name="request"></param>
        /// <param name="coupleSyncResult"></param>
        /// <returns></returns>
        public static Task[] StartMultiWorkerTasks()
        {
            Task[] tasks = new Task[3];
            tasks[0] = Task.Run(() => Console.WriteLine("do some thing 1...................."));
            tasks[1] = Task.Run(() => Console.WriteLine("do some thing 2...................."));
            tasks[2] = Task.Run(() => Console.WriteLine("do some thing 3...................."));
            return tasks;
        }
    }

  

Task示例,多线程

标签:blog   ar   div   on   art   log   line   new   as   

原文地址:http://www.cnblogs.com/mawenzhu/p/4056547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!