ExecutingStatus.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Threading;
  3. namespace Flyinsono.Client.Test.Utilities.Executors
  4. {
  5. public class ExecutingStatus
  6. {
  7. private readonly ManualResetEvent _executingEvent = new ManualResetEvent(true);
  8. private volatile bool _executing;
  9. /// <summary>
  10. /// Gets the status if is executing.
  11. /// </summary>
  12. public bool Executing
  13. {
  14. get => _executing;
  15. private set => _executing = value;
  16. }
  17. public ExecutingStatus()
  18. {
  19. _executingEvent.Set();
  20. Executing = false;
  21. }
  22. /// <summary>
  23. /// Reset the status.
  24. /// </summary>
  25. public void Reset()
  26. {
  27. _executingEvent.Reset();
  28. Executing = true;
  29. }
  30. /// <summary>
  31. /// Set the status.
  32. /// </summary>
  33. public void Set()
  34. {
  35. Executing = false;
  36. _executingEvent.Set();
  37. }
  38. /// <summary>
  39. /// Wait for the status to set.
  40. /// </summary>
  41. public void Wait()
  42. {
  43. _executingEvent.WaitOne();
  44. }
  45. public void Wait(double secondsTimeout)
  46. {
  47. _executingEvent.WaitOne(TimeSpan.FromSeconds(secondsTimeout));
  48. }
  49. }
  50. }