When I run the code below the output is \"DelegateDisplayIt\", typically repeated 1-4 times. I\'ve run this code probably 100 times, and not once has the output ever been \"
flag is a boolean variable. It is passed by value to the delegate. It will never be true, because the false value is copied and sent to the delegate.
If you use an anonymous delegate, you'll be implicitly using a closure to access the boolean value.
In .NET, the compiler constructs an anonymous type to hold the reference for the variable that is the subject of the closure (flag) which both the anonymous delegate and the method will then reference. They will then share the variable, so if one changes it both will see the change.
This really isn't a threading question, its about pass-by-value and closures. Here's a decent blog post about closures. Pass-by-value is pretty straight forward; if you need to brush up on that I'd suggest buying a copy of CLR Via C# by Jeffrey Richter.