Show / Hide Table of Contents

# Class AsyncLock

Provides a simple wrapper over a SemaphoreSlim to allow synchronization locking inside of async calls. Cannot be used recursively.

##### Inheritance

System.Object
AsyncLock

##### Inherited Members

System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()

###### Namespace:Microsoft.SqlTools.ServiceLayer.Utility

###### Assembly:Microsoft.SqlTools.ServiceLayer.dll

##### Syntax

    public class AsyncLock

### Constructors

| Improve this Doc View Source

#### AsyncLock()

Initializes a new instance of the AsyncLock class.

##### Declaration

    public AsyncLock()

### Methods

| Improve this Doc View Source

#### LockAsync()

Locks

##### Declaration

    public Task<IDisposable> LockAsync()

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.IDisposable> | A task which has an IDisposable

| Improve this Doc View Source

#### LockAsync(CancellationToken)

Obtains or waits for a lock which can be used to synchronize access to a resource. The wait may be cancelled with the given CancellationToken.

##### Declaration

    public Task<IDisposable> LockAsync(CancellationToken cancellationToken)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Threading.CancellationToken | cancellationToken | A CancellationToken which can be used to cancel the lock.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.IDisposable> |