BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object

Provides a mechanism that synchronizes access to objects.

The class controls access to objects by granting a single thread a lock for an object. Object locks provide the ability to restrict access to a block of code, commonly called a critical section. While a thread owns the lock for an object no other thread can acquire the lock for the object. Additionally, the

class can be used to ensure that no other thread can access a section of application code being executed by the lock owner, unless the other thread is executing the code using a different locked object.

The following information is maintained for each synchronized object:

A reference to the thread that currently holds the lock.

A reference to a "ready queue", which contains the threads that are ready to obtain the lock.

A reference to a "waiting queue", which contains the threads that are waiting for notification of a change in the state of the locked object.

The following table describes the actions taken by threads that access synchronized objects:

Action
Description
Enter
Acquires a lock for an object. Also marks the beginning of a critical section. No other thread can enter the critical section unless they are executing the instructions in the critical section using a different locked object. See the and methods.
Wait
Releases the lock on an object in order to permit other threads to lock and access the object. The calling thread waits while another thread accesses the object. Pulse signals (see below) are used to notify waiting threads about changes to an object's state. See .
Pulse (signal)
Sends a signal to one or more waiting threads. The signal notifies a waiting thread that the state of the locked object has changed, and the owner of the lock is ready to release the lock. The waiting thread is placed in the object's ready queue so that it can eventually receive the lock for the object. Once the thread has the lock, it can check the new state of the object to see if the required state has been reached. See and .
Exit
Releases the lock on an object. Also marks the end of a critical section protected by the locked object. See .

The and methods are used to mark the beginning and end of a critical section. If the critical section is a set of contiguous instructions, then the lock acquired by the method guarantees that only a single thread can execute the enclosed code with the locked object. This facility is typically used to synchronize access to a static or instance method of a class. If an instance method requires synchronized thread access, the instance method invokes the and corresponding methods using itself (the current instance) as the object to lock. Since only one thread can hold the lock on the current instance, the method can only be executed by one thread at a time. Static methods are protected in a similar fashion using the

object of the current instance as the locked object.

The functionality provided by the and methods is identical to that provided by the C# lock statement.

If a critical section spans an entire method, the locking facility described above can be achieved by placing the on the method, and specifying the option. Using this attribute, the and statements are not needed. Note that the attribute causes the current thread to hold the lock until the method returns; if the lock can be released sooner, use the class (or C# statement) instead of the attribute.

While it is possible for the and statements that lock and release a given object to cross member and/or class boundaries, this practice is strongly discouraged.

- Method
  System.Void `` The on which to acquire the lock.

  Acquires an exclusive lock on the specified object.

  This method acquires an exclusive lock on .

  A caller of this method is required to invoke once for each invoked.

  The caller of this method is blocked if another thread has obtained the lock by calling and specifying the same object. The caller is not blocked if the current thread holds the lock. The same thread can invoke more than once (and it will not block); however, an equal number of calls are required to be invoked before other threads waiting on the object will unblock.

  Invoking this member is identical to using the C# statement.

  is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` The on which to release the lock.

  Releases an exclusive lock on the specified .

  This method releases an exclusive lock on . The caller is required to own the lock on .

  If the caller owns the lock on the specified object, and has made an equal number of and calls for the object, then the lock is released. If the caller has not invoked as many times as , the lock is not released.

  If the lock is released and there are other threads in the ready queue for the object, one of the threads will acquire the lock. If there are other threads in the waiting queue waiting to acquire the lock, they are not automatically moved to the ready queue when the owner of the lock calls . To move one or more waiting threads into the ready queue, call or prior to invoking .

  is .

  The current thread does not own the lock for the specified object.

  0
  1.0.5000.0
  2.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
- Method
  System.Void `` The a thread might be waiting for.

  Notifies the next waiting thread (if any) of a change in the specified locked object's state.

  The thread that currently owns the lock on the specified object invokes this method to signal the next thread in line for the lock (in the queue of threads waiting to acquire the lock on the object). Upon receiving the pulse, the waiting thread is moved to the ready queue. When the thread that invoked releases the lock, the next thread in the ready queue (which is not necessarily the thread that was pulsed) acquires the lock.

  To signal a waiting object using , you must be the current owner of the lock.

  To signal multiple threads, use the method.

  is . The calling thread does not own the lock for the specified object. 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` The that one or more threads might be waiting for.

  Notifies all waiting threads (if any) of a change in the specified locked object's state.

  The thread that currently owns the lock on the specified object invokes this method to signal all threads waiting to acquire the lock on the object. After the signal is sent, the waiting threads are moved to the ready queue. When the thread that invoked releases the lock, the next thread in the ready queue acquires the lock.

  To signal waiting objects using , you must be the current owner of the lock.

  To signal a single thread, use the method.

  is . The calling thread does not own the lock for the specified object. 0 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` The on which to acquire the lock.

  Attempts to acquire an exclusive lock on the specified object.

  if the current thread acquired the lock; otherwise, .

  If successful, this method acquires an exclusive lock on . This method returns immediately, whether or not the lock is available.

  This method is equivalent to (, 0).

  is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` `` The on which to acquire the lock. A containing the maximum number of milliseconds to wait for the lock. To be added.

  Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object.

  if the current thread acquired the lock; otherwise, .

  If successful, this method acquires an exclusive lock on .

  If equals , this method is equivalent to (). If equals zero, this method is equivalent to ().

  is . is negative, and not equal to . 0 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` `` The on which to acquire the lock. A set to the maximum amount of time to wait for the lock. To be added.

  Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object.

  if the current thread acquires the lock; otherwise, .

  If successful, this method acquires an exclusive lock on .

  If the value of converted to milliseconds equals , this method is equivalent to (). If the value of equals zero, this method is equivalent to ().

  is . The value of in milliseconds is negative and is not equal to , or is greater than . 0 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` The on which to wait.

  Releases the lock on an object and blocks the current thread until it reacquires the lock.

  if the call returned because the caller reacquired the lock for the specified object. This method does not return if the lock is not reacquired.

  This method reacquires an exclusive lock on .

  The thread that currently owns the lock on the specified object invokes this method in order to release the object so that another thread can access it. The caller is blocked while waiting to reacquire the lock. This method is called when the caller is waiting for a change in the state of the object, which occurs as a result of another thread's operations on the object.

  When a thread calls , it releases the lock on the object and enters the object's waiting queue. The next thread in the object's ready queue (if there is one) acquires the lock and has exclusive use of the object. All threads that call remain in the waiting queue until they receive a signal via or sent by the owner of the lock. If is sent, only the thread at the head of the waiting queue is affected. If is sent, all threads that are waiting for the object are affected. When the signal is received, one or more threads leave the waiting queue and enter the ready queue. A thread in the ready queue is permitted to reacquire the lock.

  This method returns when the calling thread reacquires the lock on the object. Note that this method blocks indefinitely if the holder of the lock does not call or .

  The caller executes once, regardless of the number of times has been invoked for the specified object. Conceptually, the method stores the number of times the caller invoked on the object and invokes as many times as necessary to fully release the locked object. The caller then blocks while waiting to reacquire the object. When the caller reacquires the lock, the system calls as many times as necessary to restore the saved count for the caller.

  Calling releases the lock for the specified object only; if the caller is the owner of locks on other objects, these locks are not released.

  is . The calling thread does not own the lock for the specified object. 0 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` `` The on which to wait. A containing the maximum number of milliseconds to wait before this method returns.

  Releases the lock on an object and blocks the current thread until it reacquires the lock or until a specified amount of time elapses.

  if the lock was reacquired before the specified time elapsed; otherwise, .

  If successful, this method reacquires an exclusive lock on .

  This method behaves identically to (), except that it does not block indefinitely unless is specified for . Once the specified time has elapsed, this method returns a value that indicates whether the lock has been reacquired by the caller. If equals 0, this method returns immediately.

  This method is called when the caller is waiting for a change in the state of the object, which occurs as a result of another thread's operations on the object. For additional details, see ().

  is . The calling thread does not own the lock for the specified object. The value of is negative, and not equal to . 0 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` `` The on which to wait. A set to the maximum amount of time to wait before this method returns.

  Releases the lock on an object and blocks the current thread until it reacquires the lock or until a specified amount of time elapses.

  if the lock was reacquired before the specified time elapsed; otherwise, .

  If successful, this method reacquires an exclusive lock on .

  This method behaves identically to (), except that it does not block indefinitely unless milliseconds is specified for . Once the specified time has elapsed, this method returns a value that indicates whether the lock has been reacquired by the caller. If equals 0, this method returns immediately.

  This method is called when the caller is waiting for a change in the state of the object, which occurs as a result of another thread's operations on the object. For additional details, see ( ).

  is . The calling thread does not own the lock for the specified object. If is negative, and is not equal to , or is greater than . 0 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` `` `` To be added. To be added. To be added. To be added. To be added. To be added. 1.0.5000.0 2.0.0.0
- Method
  System.Boolean `` `` `` To be added. To be added. To be added. To be added. To be added. To be added. 1.0.5000.0 2.0.0.0
0 System.Runtime.InteropServices.ComVisible(true)