Asynchronous Invocation – Enumerable Extension

Thursday, January 15, 2009

I encountered several times in the following scenario: I have a list of business objects.My wish is to invoke an action on each of these objects, all of theses actions will be invoked asynchronously using the Thread Pool and it will block until all the asynchronous actions are complete. I've written a useful extension that makes this scenario very simple to code. var list = new { 1, 2, 3, 4, 5 };list.WaitAsyncForEach(i => Console.WriteLine("Invoked async for '{0}'", i)); Note - with large enumerables you might consider doing it for a certain batch size at a time, or at least modify the code to enforce...
tags: , ,
no comments