/// <summary> /// Constructor of SemaphoreSlim class /// </summary> /// <param name="context">Specify a context to have different contexts in different domains</param> /// <param name="name">Name of the new SemaphoreSlim</param> /// <param name="initialCount">The initial number of requests for the semaphoreSlim that can be granted concurrently.</param> /// <param name="maximumCount">The maximum number of requests for the semaphoreSlim that can be granted concurrently.</param> public SemaphoreSlim(Context.SemaphoreSlim context, string name, int initialCount, int maximumCount) : base(context) { ContextMapper = ctx => ctx ?? _defaultContext; if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out var tempSemaphoreSlim)) { lock (ContextMapper.Invoke(context).LockerObject) { if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out tempSemaphoreSlim)) { _currentObject = new System.Threading.SemaphoreSlim(initialCount, maximumCount); ContextMapper.Invoke(context).ObjectDictionary.TryAdd(name, _currentObject); } } } if (tempSemaphoreSlim != null) { _currentObject = (System.Threading.SemaphoreSlim)tempSemaphoreSlim; } }
/// <summary> /// Specifies the context boundary for the new SemaphoreSlim /// </summary> /// <param name="value">An instance of SemaphoreSlim context</param> /// <returns></returns> public SemaphoreSlimBuilder Context(Context.SemaphoreSlim value) { this._context = value; return(this); }