コードを考えてみましょう:
class Work
{
public void DoStuff(string s)
{
Console.WriteLine(s);
// .. whatever
}
}
class Master
{
private readonly Work work = new Work();
public void Execute()
{
string hello = "hello";
// (1) is this an ugly hack ?
var thread1 = new Thread(new ParameterizedThreadStart(o => this.work.DoStuff((string)o)));
thread1.Start(hello);
thread1.Join();
// (2) is this similar to the one above?
new Action<string>(s => this.work.DoStuff(s)).BeginInvoke(hello, null, null);
}
}
(1)別のスレッドで作業を簡単に開始するための許容できる方法ですか?そうでない場合は、より良い代替案をいただければ幸いです。
(2)同じことをしていますか?私が尋ねるのは、新しいスレッドが開始されたかどうかだと思います。
あなたが初心者がよりよく理解するのを助けることができることを願っています:)
/モーバーグ