Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.Threading.SemaphoreSlim: referencia práctica

System.Threading.SemaphoreSlim: referencia práctica: SemaphoreSlim limita las entradas simultáneas y admite WaitAsync.

Versión: .NET API; verified against .NET 10 reference surface

Sintaxis

System.Threading.SemaphoreSlim /* select a documented member or constructor */

SemaphoreSlim limita las entradas simultáneas y admite WaitAsync.

Úsalo para limitar operaciones async, liberando en finally.

Cada Wait correcto requiere un Release; un Release adicional puede lanzar SemaphoreFullException.

WaitAsync cancelado lanza OperationCanceledException; Dispose con esperas activas requiere coordinación.

El programa completo usa realmente System.Threading.SemaphoreSlim; su stdout esperado exacto es 0.

Ejemplos

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

using var semaphore = new SemaphoreSlim(1, 1);
await semaphore.WaitAsync();
Console.WriteLine(semaphore.CurrentCount);
semaphore.Release();

Resultado

0

El programa completo usa realmente `System.Threading.SemaphoreSlim`; su stdout esperado exacto es `0`.

Fuentes