FfmpegService.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.ServiceProcess;
  7. using System.Text;
  8. using EMISOnline.WinService.Common;
  9. namespace EMISOnline.WinService
  10. {
  11. partial class FfmpegService : ServiceBase
  12. {
  13. System.Timers.Timer ftpTimer; //计时器
  14. System.Timers.Timer m3u8Timer; //计时器
  15. public FfmpegService()
  16. {
  17. InitializeComponent();
  18. }
  19. protected override void OnStart(string[] args)
  20. {
  21. Log.Info("配置信息","==>");
  22. Log.Info("FtpPath", Config.FtpPath);
  23. Log.Info("FtpFileType", Config.FtpFileType);
  24. Log.Info("ServUFile", Config.ServUFile);
  25. Log.Info("M3u8Server", Config.M3u8Server);
  26. Log.Info("FTPServer", Config.FTPServer);
  27. Log.Info("DataServer", Config.DataServer);
  28. // TODO: 在此处添加代码以启动服务。
  29. ftpTimer = new System.Timers.Timer();
  30. ftpTimer.Interval = 0.2 * 60 * 1000; //设置计时器事件间隔执行时间
  31. ftpTimer.Elapsed += new System.Timers.ElapsedEventHandler(ftpTimer_Elapsed);
  32. ftpTimer.Enabled = true;
  33. m3u8Timer = new System.Timers.Timer();
  34. m3u8Timer.Interval = 1 * 60 * 1000; //设置计时器事件间隔执行时间
  35. m3u8Timer.Elapsed += new System.Timers.ElapsedEventHandler(m3u8Timer_Elapsed);
  36. m3u8Timer.Enabled = true;
  37. }
  38. protected override void OnStop()
  39. {
  40. // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
  41. }
  42. private bool ftpTimerRuning = false;
  43. private void ftpTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  44. {
  45. //每次检查文件维持单线程检查,多余的次数触发直接跳过
  46. if (!ftpTimerRuning)
  47. {
  48. ftpTimerRuning = true;
  49. try
  50. {
  51. new FtpTimer().CheckFiles();
  52. }
  53. catch (Exception ex)
  54. {
  55. Log.Error(this.GetType().ToString(), ex.Message + ex.ToString());
  56. }
  57. ftpTimerRuning = false;
  58. }
  59. }
  60. private bool m3u8TimerRuning = false;
  61. private void m3u8Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  62. {
  63. //每次转换维持单线程,多余的次数触发直接跳过
  64. if (!m3u8TimerRuning)
  65. {
  66. m3u8TimerRuning = true;
  67. try
  68. {
  69. new M3u8Timer().doingM3u8();
  70. }
  71. catch (Exception ex)
  72. {
  73. Log.Error(this.GetType().ToString(), ex.Message + ex.ToString());
  74. }
  75. m3u8TimerRuning = false;
  76. }
  77. }
  78. }
  79. }