C#交流俱乐部

学习为主,互相帮助

博客园 首页 新随笔 联系 订阅 管理
1.对于没有参数的线程

Thread T= new Thread(new ThreadStart(*));

2.对于有参数的线程

Thread T= new Thread(new ParameterizedThreadStart(*));

 

 --------------------------------

msdn上代码:

----------------------------------

class work

{

 public static void Main(string[] args)

{

            // To start a thread using a shared thread procedure, use
            // the class name and method name when you create the
            // ParameterizedThreadStart delegate. C# infers the
            // appropriate delegate creation syntax:
            //    new ParameterizedThreadStart(work.DoWork)
            //
            Thread newThread = new Thread(work.DoWork);

            // Use the overload of the Start method that has a
            // parameter of type Object. You can create an object that
            // contains several pieces of data, or you can pass any
            // reference type or value type. The following code passes
            // the integer value 42.
            //
            newThread.Start(42);

            // To start a thread using an instance method for the thread
            // procedure, use the instance variable and method name when
            // you create the ParameterizedThreadStart delegate. C# infers
            // the appropriate delegate creation syntax:
            //    new ParameterizedThreadStart(w.DoMoreWork)
            //
            work w = new work ();
            newThread = new Thread(w.DoMoreWork);

            // Pass an object containing data for the thread.
            //
            newThread.Start("The answer.");

}

         public static void DoWork(object data)
        {
            Console.WriteLine("Static thread procedure. Data='{0}'",
                data);
        }

        public void DoMoreWork(object data)
        {
            Console.WriteLine("Instance thread procedure. Data='{0}'",
                data);
        }

}

posted on 2010-06-03 14:36  bluce chen  阅读(238)  评论(0编辑  收藏  举报