线程的几种用法

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

线程的几种用法

上一篇:转VS2010解决方案转换到VS2008


下一篇:hibernate注解自动生成数据表出不来?