CameraBase.cs 1009 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Threading;
  3. namespace TeamAAS_VP.Core.Cameras
  4. {
  5. /// <summary>
  6. /// Base class for camera implementations. Provides per-instance locking and state lock
  7. /// to serialize operations on the same camera instance and protect state changes (e.g., IsGrabbing).
  8. /// </summary>
  9. public abstract class CameraBase
  10. {
  11. // Semaphore to serialize operations on the same instance
  12. protected readonly SemaphoreSlim _operationSemaphore = new SemaphoreSlim(1, 1);
  13. // Lock for protecting state properties like IsGrabbing
  14. protected readonly object _stateLock = new object();
  15. protected void EnterOperation()
  16. {
  17. _operationSemaphore.Wait();
  18. }
  19. protected void ExitOperation()
  20. {
  21. try
  22. {
  23. _operationSemaphore.Release();
  24. }
  25. catch (SemaphoreFullException)
  26. {
  27. // ignore if already released
  28. }
  29. }
  30. }
  31. }