I was wondering how using lock
prevents the System.Threading.Timer from overlapping the portion of code inside the lock
statement but not the code outside it! ?, how is it working.
Presumably because you've got multiple threads locking on the same object.
The whole point of a lock
statement is that only one thread can acquire any particular monitor at a time. If they didn't do that, they'd be pretty pointless! If your timer threads were to try to acquire different monitors, they'd all be able to run concurrently.
If that doesn't help, please read MSDN on the lock
statement, and then post a more specific question if you're still confused.
See more on this question at Stackoverflow