Comment créer et démarrer un thread paramétré dans .NET 1.1?
-
22-07-2019 - |
Question
.NET 1.1 manque de ParameterizedThreadStart
(je dois utiliser 1.1 car c'est le dernier supportant NT 4.0)
Dans .NET 2.0, j'écrirais simplement:
Thread clientThread = new Thread(new ParameterizedThreadStart(SomeThreadProc));
clientThread.Start(someThreadParams);
Comment créer un code .NET 1.1 équivalent?
La solution
Vous devez créer une classe pour l'état:
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();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow