Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In C#.NET, is there an implemention like Java's CompletionService?

I just need to convert the simple Java codes below to Equivalent C#.net codes.

Java
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();



For 'ExcutorService', I can think of using C#'s 'ThreadPool' to replace it. But for 'ExcutorCompletionService' , I have searched for one day on google and have got nothing.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900