C#, IAsyncResult and the thread pool

﹥>﹥吖頭↗ 提交于 2019-12-01 17:44:53

问题


I use the Action<object>.BeginInvoke() method, does this use the thread pool or not?

I have the following C# code:

    List<FileHash> hashList1 = hashList.Where((x, ind) => ind % 2 == 0).ToList();
    List<FileHash> hashList2 = hashList.Where((x, ind) => ind % 2 == 1).ToList();

    Action<object> oddWork = CalcHash;
    Action<object> evenWork = CalcHash;

    IAsyncResult evenHandle = evenWork.BeginInvoke(hashList1, null, null);
    IAsyncResult oddHandle = oddWork.BeginInvoke(hashList2, null, null);

    evenWork.EndInvoke(evenHandle); 
    oddWork.EndInvoke(oddHandle);

Is the thread pool used behind the scenes or not? Or does the system create normal threads?


回答1:


Yes this work will occur in the thread pool. This page in MSDN goes into depth on how BeginInvoke works:

http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx



来源:https://stackoverflow.com/questions/442991/c-iasyncresult-and-the-thread-pool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!