JobTimer.cs 942 B

12345678910111213141516171819202122232425262728293031
  1. using Furion.Logging;
  2. using Furion.TaskScheduler;
  3. namespace Admin.NET.Application.Serice;
  4. /// <summary>
  5. /// 任务调度测试
  6. /// </summary>
  7. public class JobTimer : ISpareTimeWorker
  8. {
  9. /// <summary>
  10. /// 定时器
  11. /// </summary>
  12. /// <param name="timer"></param>
  13. /// <param name="count"></param>
  14. [SpareTime(5000, "定时器", StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
  15. public void CollectDeviceChannel(SpareTimer timer, long count)
  16. {
  17. //// 写日志文件
  18. //StringLoggingPart.Default.SetMessage("这是一个日志").LogInformation();
  19. Scoped.Create((_, scope) =>
  20. {
  21. var services = scope.ServiceProvider;
  22. var db = services.GetService<ISqlSugarClient>();
  23. // 写日志文件
  24. StringLoggingPart.Default.SetMessage("【定时器】" + DateTime.Now + "执行次数:" + count).LogInformation();
  25. });
  26. }
  27. }