Long function as a lambda, right or wrong? I have been reviewing the code of a new co-worker and, although in general I think it's OK, there's a thing that causes me mixed feelings:

  private void Method(...)
  {
       Thread t = new Thread(() =&gt;
       {
           // Some ~50 lines of code here
       });
       t.Start();
  }


This is no big deal, but I'm curious about what you guys think of it.
Is this exactly what lambdas are for? Or just the opposite? I try to avoid any lambda which doesn't fit on a couple lines at most...
I think it should be a separate method rather than a lambda expression. If the method is as large as 50 lines then you should seriously think about breaking it up anyway, being an anonymous method only compounds the issue. It may be better to extract portions of the method instead, but that is a decision that you will need to make based on the actual code in the method.

My general rule-of-thumb is that if an anonymous method spans more than half the screens height then it's too big and should be a separate named method.



Update in response to Timwi's comments:

When a method is well named, the name helps to describe what the method is intended to do, both where it is used and where it is defined. Anonymous methods don't get this, and so to understand it you need to rely on the context more. This is fine when if the anonymous method is simple but if its large and/or there is deep nesting involved (within or containing various control structures) the behavior can become much less obvious.

The "exact" example used by the OP is not too bad because the containing method is very simple, but I don't see any real benefit (for either performance or readability) and so would still prefer to have it as a separate method.

Of-course, "readability" is a bit subjective. Most people will agree on the extreme cases but the edge cases are probably better discussed with, and a consensus drawn from those actually responsible for maintaining it.