• 线程传参数


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

    }

  • 相关阅读:
    apue学习笔记(第一章UNIX基础知识)
    批处理之发布新版本
    在Vista或Windows 7系统上安装Sharepoint 2007
    SharePoint Server 2007 简体中文下载
    sql连接字符串的方法
    共享本地的无线网络
    FastReport报表
    C# 语音识别(文字to语音、语音to文字)
    C#调用脚本语言(三)-- IronJS 与 IronLua 简单方法性能比较
    VS2010中出现无法嵌入互操作类型
  • 原文地址:https://www.cnblogs.com/wyxy2005/p/1750743.html
Copyright © 2020-2023  润新知