using System; using System.Threading; namespace TeamAAS_VP.Core.Cameras { /// /// Base class for camera implementations. Provides per-instance locking and state lock /// to serialize operations on the same camera instance and protect state changes (e.g., IsGrabbing). /// public abstract class CameraBase { // Semaphore to serialize operations on the same instance protected readonly SemaphoreSlim _operationSemaphore = new SemaphoreSlim(1, 1); // Lock for protecting state properties like IsGrabbing protected readonly object _stateLock = new object(); protected void EnterOperation() { _operationSemaphore.Wait(); } protected void ExitOperation() { try { _operationSemaphore.Release(); } catch (SemaphoreFullException) { // ignore if already released } } } }