I have 3 questions that I need help with.

  1. What are the correct objects/references to be passed as lock statement 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 modifier static is 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.

  2. I found a sample code in MSDN about multi threading that uses lock statements too. In the sample there are two try/catch blocks with the Monitor.Wait() within it. If I understand the logic correctly, the readerFlag will forbid the program to ever enter the try/catch block at all.
    The code is example 2 from here:
    http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx

  3. How do I run a thread that runs in the background as long as the Windows Form is active?

Edit
Report