ITimedEvents.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. namespace Terminal.Gui.App;
  2. /// <summary>
  3. /// Manages timers.
  4. /// </summary>
  5. public interface ITimedEvents
  6. {
  7. /// <summary>
  8. /// Adds a timeout to the application.
  9. /// </summary>
  10. /// <remarks>
  11. /// When the specified time passes, the callback will be invoked. If the callback returns <see langword="true"/>, the
  12. /// timeout will be
  13. /// reset, repeating the invocation. If it returns <see langword="false"/>, the timeout will stop and be removed. The
  14. /// returned value is a
  15. /// token that can be used to stop the timeout by calling <see cref="Remove"/>.
  16. /// </remarks>
  17. object Add (TimeSpan time, Func<bool> callback);
  18. /// <inheritdoc cref="Add(System.TimeSpan,System.Func{bool})"/>
  19. object Add (Timeout timeout);
  20. /// <summary>
  21. /// Invoked when a new timeout is added. To be used in the case when
  22. /// <see cref="IApplication.StopAfterFirstIteration"/> is <see langword="true"/>.
  23. /// </summary>
  24. event EventHandler<TimeoutEventArgs>? Added;
  25. /// <summary>
  26. /// Removes a previously scheduled timeout.
  27. /// </summary>
  28. /// <remarks>
  29. /// The token parameter is the value returned by <see cref="Add(TimeSpan, Func{bool})"/> or <see cref="Add(Timeout)"/>.
  30. /// </remarks>
  31. /// <returns>
  32. /// <see langword="true"/> if the timeout is successfully removed; otherwise, <see langword="false"/>.
  33. /// This method also returns <see langword="false"/> if the timeout is not found.
  34. /// </returns>
  35. bool Remove (object token);
  36. /// <summary>
  37. /// Runs all timeouts that are due.
  38. /// </summary>
  39. void RunTimers ();
  40. /// <summary>
  41. /// Returns the next planned execution time (key - UTC ticks)
  42. /// for each timeout that is not actively executing.
  43. /// </summary>
  44. SortedList<long, Timeout> Timeouts { get; }
  45. }