System.Threading.SemaphoreSlim.Release C# (CSharp) Méthode

Release() public méthode

public Release ( int releaseCount ) : int
releaseCount int
Résultat int
		public int Release (int releaseCount)
		{
			CheckState ();
			if (releaseCount < 0)
				throw new ArgumentOutOfRangeException ("releaseCount", "	The releaseCount must be positive.");
			
			// As we have to take care of the max limit we resort to CAS
			int oldValue, newValue;
			do {
				oldValue = currCount;
				newValue = (currCount + releaseCount);
				newValue = newValue > max ? max : newValue;
			} while (Interlocked.CompareExchange (ref currCount, newValue, oldValue) != oldValue);
			
			return oldValue;
		}
		

Same methods

SemaphoreSlim::Release ( ) : int

Usage Example

        private const int GameCacheDuration = 43200; // 12 hours

        public async Task<GameDetails[]> ParallelLoadGames(IEnumerable<int> gameIds)
        {
            GameDetails[] results;
            var tasks = new List<Task<GameDetails>>();
            using (var throttler = new SemaphoreSlim(5))
            {
                foreach (var gameId in gameIds)
                {
                    await throttler.WaitAsync();
                    tasks.Add(Task<GameDetails>.Run(async () =>
                    {
                        try
                        {
                            Debug.WriteLine("Loading {0}...", gameId);
                            return await this.LoadGame(gameId, true);
                        }
                        finally
                        {
                            Debug.WriteLine("Done with {0}...", gameId);
                            throttler.Release();
                        }
                    }));

                }
                results = await Task.WhenAll(tasks);
            }
            return results;
        }
All Usage Examples Of System.Threading.SemaphoreSlim::Release