StartupTrigger.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Threading.Tasks;
  3. using MediaBrowser.Model.Events;
  4. namespace MediaBrowser.Common.ScheduledTasks
  5. {
  6. /// <summary>
  7. /// Class StartupTaskTrigger
  8. /// </summary>
  9. public class StartupTrigger : ITaskTrigger
  10. {
  11. public int DelayMs { get; set; }
  12. /// <summary>
  13. /// Gets the execution properties of this task.
  14. /// </summary>
  15. /// <value>
  16. /// The execution properties of this task.
  17. /// </value>
  18. public TaskExecutionOptions TaskOptions { get; set; }
  19. public StartupTrigger()
  20. {
  21. DelayMs = 3000;
  22. }
  23. /// <summary>
  24. /// Stars waiting for the trigger action
  25. /// </summary>
  26. /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
  27. public async void Start(bool isApplicationStartup)
  28. {
  29. if (isApplicationStartup)
  30. {
  31. await Task.Delay(DelayMs).ConfigureAwait(false);
  32. OnTriggered();
  33. }
  34. }
  35. /// <summary>
  36. /// Stops waiting for the trigger action
  37. /// </summary>
  38. public void Stop()
  39. {
  40. }
  41. /// <summary>
  42. /// Occurs when [triggered].
  43. /// </summary>
  44. public event EventHandler<GenericEventArgs<TaskExecutionOptions>> Triggered;
  45. /// <summary>
  46. /// Called when [triggered].
  47. /// </summary>
  48. private void OnTriggered()
  49. {
  50. if (Triggered != null)
  51. {
  52. Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions));
  53. }
  54. }
  55. }
  56. }