SemaphoreSlim Constructor (Int32)
Collapse the table of content
Expand the table of content

SemaphoreSlim Constructor (Int32)

.NET Framework (current version)
 

Initializes a new instance of the SemaphoreSlim class, specifying the initial number of requests that can be granted concurrently.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public SemaphoreSlim(
	int initialCount
)

Parameters

initialCount
Type: System.Int32

The initial number of requests for the semaphore that can be granted concurrently.

Exception Condition
ArgumentOutOfRangeException

initialCount is less than 0.

The initialCount parameter defines the number of concurrent requests to enter the semaphore that can be granted. However, it doesn’t define the maximum number of requests that can be granted concurrently. A SemaphoreSlim object instantiated by calling this constructor doesn’t throw a SemaphoreFullException exception if a call to the Release method increases the value of the CurrentCount property beyond initialCount. This occurs if there are more calls to Release methods than there are to Wait or WaitAsync methods. To set the maximum number of concurrent requests to enter the semaphore that can be granted, call the SemaphoreSlim(Int32, Int32) constructor.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft