首页 > 其他 > 详细

线程的几种用法

时间:2014-01-24 22:51:21      阅读:521      评论:0      收藏:0      [点我收藏+]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            ////线程方法1
            //if (ThreadPool.QueueUserWorkItem(new WaitCallback(Program.WritePara), "这是传进去的参数"))
            //{
            //    Console.WriteLine("ok:");
            //    Console.Read();
            //}
            //线程方法2
            Thread th = new Thread(new ThreadStart(Write));
            th.Start();
            //线程方法3
            Thread thread = new Thread(new ParameterizedThreadStart(WritePara));
            thread.Start("Thread thread = new Thread( new ParameterizedThreadStart(WritePara))有参传递");


        }
        protected static void WritePara(object para)
        {
            Console.WriteLine("hello:" + para);
        }

        private static void Write()
        {
            Console.WriteLine(" Thread th = new Thread(new ThreadStart(Write));无参线程调用");
        }
    }
}

线程的几种用法

原文:http://www.cnblogs.com/yexinw/p/3532530.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!