zoukankan      html  css  js  c++  java
  • 线程传参数

    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);
            }

    }

  • 相关阅读:
    获取服务器的IP地址和MAC地址
    silverlight学习:RichTextBox[转]
    历次重要底部的数据特征 A股或将继续下跌?
    Silverlight开发工具集合[转]
    每个.NET 开发人员应该下载的十个必备工具
    VS 发布网站时如何产生固定命名的 Dll 文件 WebDeploymentSetup使用说明
    匈牙利命名法、骆驼命名法、帕斯卡(pascal)命名法 C#命名规范
    让你在股市中战无不胜的八大技巧
    C#编程规范
    Enterprise Architect 8.0 注册码及其使用教程
  • 原文地址:https://www.cnblogs.com/wyxy2005/p/1750743.html
Copyright © 2011-2022 走看看