メンバー関数用の新しいスレッドを作成したいと思います。私は現在このコードを使用していますが、
Thread thread = new Thread(new ThreadStart(c.DoSomethingElse));
thread.Start();
そしてそれは働いています。しかし、メンバー関数をパラメーター化したいと思います。
私はこのクラスを持っています:
class C1 {
public void DoSomething() {}
public void DoSomethingElse() {}
public delegate void myDelegate(C1 c);
}
次に、他のクラスにこの関数があります。
public void myFunction(C1.myDelegate func) {
C1 c = new C1();
func(c); // this is working
// but I want that the called function runs in it's own thread
// so I tried...
Thread thread = new Thread(new ThreadStart( func(c) ); // but the compile wants a
thread.Start(); // method name and not a delegate
}
次のように myFunction を呼び出します...
myFunction( (c) => c.DoSomething() );
これを行うことは可能ですか。つまり、デリゲートを渡し、オブジェクト func(c) で呼び出すことができます。そして、object.memberfunction を渡す新しいスレッドを作成できます。しかし、 memberfunction デリゲートを使用して ThreadStart 関数に渡すことで、両方を組み合わせる方法がわかりません。ヒントはありますか?