ForEach method and blonde me

I want to tell you about List<T>.ForEach method and one of my famous blonde moments when I was debugging faulty code. LINQ makes it easy to query collections and that’s why I like it a lot. Today is friday and weekend is coming. Let’s relax and have some fun on me. Here’s one proof how n00b I can be :)

Well, there was a simple code that readed updated information from outer sources and suddenly there was faulty source that stopped updating process. The code was something like this.

try
{
    sources.ForEach(a => UpdateListCache());
}
catch (Exception ex)
{
    Log(ex.ToString());
}

Why this process stopped?

Well, it turns out that update method of source proxies had no exception handling and first exception that occured stopped the ForEach. So, if you see something similiar and think what may be the problem then check the method that is called in ForEach method to find out what’s going on there.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    Leave a Reply

    Your email address will not be published. Required fields are marked *