Release
Release возвращает допуск. Сверх максимума бросает SemaphoreFullException.
Синтаксис
int count = sem.Release();
Пример
Давайте вернём допуск после Wait:
using System;
using System.Threading;
class Program
{
static void Main()
{
var sem = new SemaphoreSlim(1, 1);
sem.Wait(0);
sem.Release();
Console.WriteLine(sem.CurrentCount);
}
}
Результат выполнения кода:
1
Пример
Давайте вызовем лишний Release:
using System;
using System.Threading;
class Program
{
static void Main()
{
var sem = new SemaphoreSlim(1, 1);
sem.Wait(0);
sem.Release();
try
{
sem.Release();
Console.WriteLine("ok");
}
catch (SemaphoreFullException)
{
Console.WriteLine("fail");
}
}
}
Результат выполнения кода:
"fail"
Смотрите также
-
Wait,
занять допуск -
CurrentCount,
свободно -
SemaphoreSlim,
SemaphoreSlim -
Lock,
Lock