The difference between the two is that second block of code will not prevent anything from being executed on the executing thread before you DoStuff.
Example:
lock (stuff) {
InvokeOnMainThread ( delegate { Console.WriteLine ("a"); } }
}
Console.WriteLine ("b");
will print:
a
b
while this code:
InvokeOnMainThread ( delegate {
lock (stuff) {
Console.WriteLine ("a");
}
}
Console.WriteLine ("b");
will usually (but not necessarily) print:
b
a
Now this doesn't explain why the second block would fix the race condition, but my guess would be that it would just change the race condition enough for you to not hit it again (so not fix it, just hide it).