I am wondering what will happen if there is a lock inside IEnumerable method.
for example a program like this:
IEnumerable<int> Foo()
{
....
lock(...)
{
yield return ...;
}
}
Since IEnumerable is delay executed, and does not generate all the results at once, what will the lock do inside the method? Will it unlock after each element generation or will it hold on to the lock until the IEnumerable object is GCed? Or something else?