在C#.NET中,是否有像Java的CompletionService这样的实现?

时间:2015-11-17 06:15:07

标签: java c# threadpool executorservice completion-service

在stackowerflow上已经存在类似的问题:link。 但它的内容对我来说太难了,我无法理解lambda的表达。

我只需要将下面的简单Java代码转换为Equivalent C#.net代码。

ExecutorService pool = null;
pool = Executors.newFixedThreadPool(BaseBlockUtil.THREAD_NUN);
CompletionService<BlockObject> completionService = new ExecutorCompletionService<BlockObject>(pool);        
int runnerThread = 0;
foreach (BlockObject blockObject in putExtra.processes)
{
    runnerThread++;
    while (runnerThread > (BaseBlockUtil.THREAD_NUN + 1))
    {
        completionService.take().get();
        runnerThread--;
    }
    BlockUpload task = new BlockUpload(blockObject, jsonObjectRet, putExtra, token, httpClient, uploadBatch);
    completionService.submit(task);
}

for (int i = 0; i < runnerThread; i++)
{
    completionService.take().get();
}
pool.shutdown();

对于&#39; ExcutorService&#39;,我可以考虑使用C#&#39; ThreadPool&#39;替换它。但是对于ExcutorCompletionService&#39; ,我在谷歌搜索了一天,什么都没有。

关于&#39; ExcutorCompletionService&#39;的功能,您可以参考此When should I use a CompletionService over an ExecutorService?

0 个答案:

没有答案