线程的几种用法

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));无参线程调用");
        }
    }
}

posted @ 2014-01-24 15:41  易独  阅读(365)  评论(0编辑  收藏  举报
乐巴儿 一个有声音的公众号
长按,识别二维码,加关注