如何在.NET 1.1中创建和启动参数化线程?

时间:2008-12-03 15:12:14

标签: c# multithreading .net-1.1 nt4

.NET 1.1缺少ParameterizedThreadStart(我必须使用1.1,因为它是支持NT 4.0的最后一个)

在.NET 2.0中,我只想写:

Thread clientThread = new Thread(new ParameterizedThreadStart(SomeThreadProc));
clientThread.Start(someThreadParams);

如何创建等效的.NET 1.1代码?

1 个答案:

答案 0 :(得分:5)

您需要为州创建一个类:

class Foo {
  private int bar;
  public Foo(int bar) { // and any other args
      this.bar = bar;
  }    
  public void DoStuff() {
     // ...something involving "bar"
  } 
}
...
Foo foo = new Foo(12);
Thread thread = new Thread(new ThreadStart(foo.DoStuff));
thread.Start();