you cannot pass variables this way, use a member variable instead

解决方案 »

  1.   

    使用ThreadPool.QueueUserWorkItem 方法,应该是可以的。详见
    <FrameworkSDK>\Samples\Technologies\Threading\下的例子。
      

  2.   

    最好的办法就是线程启动另一个类的Method,参数则以类的字段或属性传入。还有就是用QueueUserWorkItem这个问题以前讨论过,微软的兄弟就推荐第一个。
      

  3.   

    两种简单的方法:using System;
    using System.Threading;namespace ConsoleApplication2
    {
    class Class1
    {
    [STAThread]
    static void Main(string[] args)
    {
    new eg1().Start();
    new eg2().Start(); Console.ReadLine();
    }
    }
    class eg1
    {
    public void Start()
    {
    new DoJobDelegate(DoJob).BeginInvoke("aaa async",null,null);
    DoJob("aaa sync");
    }
    private delegate void DoJobDelegate(string msg);
    private void DoJob(string msg)
    {
    Console.WriteLine(msg);
    }
    }
    class eg2
    {
    public void Start()
    {
    new DoJobScope(this,"bbb async");
    DoJob("bbb sync");
    }
    private class DoJobScope
    {
    eg2 p;
    string msg;
    public DoJobScope(eg2 p,string msg)
    {
    this.p=p;
    this.msg=msg;
    new Thread(new ThreadStart(Start)).Start();
    }
    private void Start()
    {
    p.DoJob(msg);
    }
    }
    private void DoJob(string msg)
    {
    Console.WriteLine(msg);
    }
    }
    }
      

  4.   

    同意刀兄的方法,例:class a{
     public string b = "";
     public void c(){
      //todo: code here
     }
    }
    class d{
     a obj = new a();
     obj.b = "ok"; //传参
     Thread t = new Thread(new ThreadStart(a.c));
     t.Start();
    }