C# では、デリゲートを使用して非同期的に作業を行う (BeginInvoke() を呼び出す) ことと、以下に示すように ThreadPool スレッドを使用することの間に違いはありますか?
public void asynchronousWork(object num)
{
//asynchronous work to be done
Console.WriteLine(num);
}
public void test()
{
Action<object> myCustomDelegate = this.asynchronousWork;
int x = 7;
//Using Delegate
myCustomDelegate.BeginInvoke(7, null, null);
//Using Threadpool
ThreadPool.QueueUserWorkItem(new WaitCallback(asynchronousWork), 7);
Thread.Sleep(2000);
}
編集:
BeginInvoke は、スレッド プールのスレッドが非同期コードの実行に使用されるようにします。違いはありますか?