我想写这么一个线程
                 
   Thread k = new Thread(new ThreadStart(copyFile(newLogicDisc[0],aimPath)));   可是VS提示说“应输入方法名称”,换句话说“方法不该带参数”
   但是我改成这样   Thread k = new Thread(new ThreadStart(copyFile));   这个又不是我写的方法,因为我写的方法需要传参数。。   请问我该如何在ThreadStart的方法中添加我需要的参数???
   

解决方案 »

  1.   

    k.Start( parameter );
      

  2.   


    Thread k = new Thread(new ThreadStart
    怎么写?
      

  3.   

    LZ结贴了!!!!可以这样:
    //直接用方法名声明线程
     Thread thread = new Thread(copyFile);
    //线程运行,传入copyFile的参数
     thread.Start(obj);
      

  4.   

    我的VS2008提示错误“Start”方法没有采用“2”个参数的重载
      

  5.   

    ParameterizedThreadStart只能带一个参数,但你可以自己定义该参数:void CopyFile(object state)
    {
       MyTask task = state as MyTask;
       copyFile( task.Source, task.Destination );
    }Thread k = new Thread( new ParameterizedThreadStart(CopyFile) );
    MyTask task = new MyTask(newLogicDisc[0],aimPath);
    k.Start( task );
      

  6.   

    //线程代理的方法
    copyFile(object obj);//声明一个组合类或者结构体传给obj,包含你的参数newLogicDisc[0],aimPath就可以了
      

  7.   

    (copyFile(newLogicDisc[0],aimPath))这有问题.参数不在这里写.这里只写方法名
      

  8.   

    MyTask 又从哪儿来的???using什么??
      

  9.   


    你自己写:)
    叫它YourTask也可以,直接用object[2]也可以(不过可读性不好),能打包两个参数就可以。
      

  10.   

    public delegate void copyFile(类型 newLogicDisc[0],类型 aimPath );
    Thread k = new Thread(new ThreadStart(copyFile));
    k.Start();
      

  11.   

    比如声明结构体
     Strut MyParameter 
        {
    private String newLogicDisc;
    private String aimPath;
    //其他定义
         }
    初始化一个MyParameter thread.Start(myParameter );
      

  12.   

    你的意思是吧方法声明为delegate就ok??可惜不行啊。
      

  13.   

    copyFile 的参数改成obj的,然后用
    Thread k = new Thread(new ThreadStart(copyFile)); 
    k.start(你的参数);
      

  14.   

    用Action委托 直接调用方法
      

  15.   

    http://www.cnblogs.com/OceanChen/archive/2009/02/02/1382426.html
      

  16.   

    Thread.Start 方法 (Object)using System;
    using System.Threading;public class Work
    {
        public static void Main()
        {
            // 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);
        }
    }/* This code example produces the following output (the order 
       of the lines might vary):Static thread procedure. Data='42'
    Instance thread procedure. Data='The answer'
    */
      

  17.   

    就是把你的copyFile的那2个参数
    包装到一个类里面lz结贴-----------------------------------------
    虽我拥有此宇宙, 无有一物为我留, 因我不可知未知, 如我不愿弃已知
      

  18.   

    这样是可以的
    //申明
    private System.Threading.Thread thread;
    private void button1_Click(object sender, EventArgs e)
    {
    this.thread = new System.Threading.Thread(this.copyFile);
    this.thread.start("AAA");
    }//下面是你需要在线程里面运行的函数。不需要用到委托
            private void copyFile1(object ss) 
            { 
               MessageBox.Show(ss.ToString());
            }绝对可以