Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Threading.​Lock

Assembly: System.Runtime

Inheritance: object → Lock

Provides a mechanism for achieving mutual exclusion in regions of code between different threads.

Properties

public bool
IsHeldByCurrentThread
Gets a value that indicates whether the lock is held by the current thread.

Methods

public void
Enter​()
Enters the lock, waiting if necessary until the lock can be entered.
public Scope
EnterScope​()
Returns A <see cref="T:System.Threading.Lock.Scope" /> that can be disposed to exit the lock.
Enters the lock, waiting if necessary until the lock can be entered.
public void
Exit​()
Exits the lock.
public bool
TryEnter​()
Returns <see langword="true" /> if the lock was entered by the current thread; otherwise, <see langword="false" /> .
Tries to enter the lock without waiting.
public bool
TryEnter​(int millisecondsTimeout)
millisecondsTimeout The number of milliseconds to wait until the lock can be entered. Specify <see cref="F:System.Threading.Timeout.Infinite">Timeout.Infinite</see> ( <code>-1</code> ) to wait indefinitely, or <code>0</code> to not wait.
Returns <see langword="true" /> if the lock was entered by the current thread; otherwise, <see langword="false" /> .
Tries to enter the lock, waiting if necessary for the specified number of milliseconds until the lock can be entered.
public bool
TryEnter​(TimeSpan timeout)
timeout A <see cref="T:System.TimeSpan" /> that represents the number of milliseconds to wait until the lock can be entered. Specify a value that represents <see cref="F:System.Threading.Timeout.Infinite">Timeout.Infinite</see> ( <code>-1</code> ) milliseconds to wait indefinitely, or a value that represents <code>0</code> milliseconds to not wait.
Returns <see langword="true" /> if the lock was entered by the current thread; otherwise, <see langword="false" /> .
Tries to enter the lock, waiting if necessary until the lock can be entered or until the specified timeout expires.
public bool
Equals​(object obj)
Inherited from object
obj The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Returns A hash code for the current object.
Serves as the default hash function.
public Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns A string that represents the current object.
Returns a string that represents the current object.