I have 3 questions that I need help with.
What are the correct objects/references to be passed as
lockstatement parameter? I've seen a lot of sample codes and I noticed that the objects/references passed in could possibly be non related to the current class or any other class in the program as long as the access modifierstaticis non public? E.g.:private Object anyObj = new Object(); lock(anyObj){.....} private static readonly object Locker = new object(); lock(Locker){.....}It just doesn't make sense to me.
I found a sample code in MSDN about multi threading that uses
lockstatements too. In the sample there are twotry/catchblocks with theMonitor.Wait()within it. If I understand the logic correctly, thereaderFlagwill forbid the program to ever enter thetry/catchblock at all.
The code is example 2 from here:
http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspxHow do I run a thread that runs in the background as long as the Windows Form is active?