Come posso creare e avviare un thread con parametri in .NET 1.1?
-
22-07-2019 - |
Domanda
.NET 1.1 non ha ParameterizedThreadStart
(devo usare 1.1 perché è l'ultimo che supporta NT 4.0)
In .NET 2.0, scriverei semplicemente:
Thread clientThread = new Thread(new ParameterizedThreadStart(SomeThreadProc));
clientThread.Start(someThreadParams);
Come posso creare un codice .NET 1.1 equivalente?
Soluzione
Dovresti creare una classe per lo stato:
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();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow