| 12345678910111213141516171819202122232425262728293031323334 |
- using System;
- using System.Threading;
- namespace TeamAAS_VP.Core.Cameras
- {
- /// <summary>
- /// 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).
- /// </summary>
- 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
- }
- }
- }
- }
|