新建Timer类

using BaseAsset.Data.Infrastructure;
using BaseAsset.Data.Repositories;
using BaseAsset.Entities;
using BaseAsset.Services;
using BaseAsset.Services.Abstract;
using System;
using System.Threading;
using System.Timers; namespace BaseAsset.Api.Timer
{
public class CostanalysisTimer
{
private static int inTimer = 0;
public void SetTimer()
{
System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed += new ElapsedEventHandler(OnTimer);
//aTimer.Interval = 60000;
aTimer.Interval = 10800000;
aTimer.Enabled = true;
}
public void OnTimer(Object source, ElapsedEventArgs e)
{
try
{
//防止重入问题
if (Interlocked.Exchange(ref inTimer, 1) == 0)
{
IFoodService _foodService = new FoodService(
new EntityBaseRepository<fd_purchase>(),
new EntityBaseRepository<fd_purchase_detail>(),
new EntityBaseRepository<fd_cost_analysis>(),
new EntityBaseRepository<fd_cost_analysis_detail>(), new UnitOfWork());//工作单元实例化(工作单元的接入,保证了数据上下文在一个操作单元中只有一个,它可以通过构造方法注入到其它类中,实现跨类进行方法的组合。)
_foodService.Addcostanalysis();
Interlocked.Exchange(ref inTimer, 0);
}
}
catch (Exception ex)
{
Interlocked.Exchange(ref inTimer, 0);
throw (ex);
} }
}
}
Global.asax
using BaseAsset.Api.Mappings;
using BaseAsset.Api.Timer;
using System.Web.Http; namespace BaseAsset.Api
{
public class WebApiApplication : System.Web.HttpApplication
{ protected void Application_Start()
{
CostanalysisTimer time = new CostanalysisTimer();
time.SetTimer();
} }
}
 

最新文章

  1. SQL Server 2012 The report server cannot open a connection to the report server database
  2. Html登录表单阻止自动填充
  3. java的重写规则
  4. linux下重启tomcat,日志查看
  5. Technical analysis of client identification mechanisms
  6. WebForm上传文件FileUpload
  7. tomcat服务器配置多个项目
  8. Live555研究之三 RTSP Server处理请求
  9. 《精通CSS:高级Web标准解决方案》学习笔记(上)
  10. 如何快速方便的输出向量vector容器中不重复的内容
  11. SCOPE_IDENTITY()
  12. 线上Django项目python2到3升级日记
  13. expdp/impdp数据泵用法
  14. 【Java】浅谈Java IO
  15. report源码分析——report_handle和report_server和report_catcher
  16. Ubuntu下搭建Hyperledger Fabric v1.0环境
  17. JDBC 查询的三大参数
  18. Spark Storage(一) 集群下的区块管理
  19. AE IRasterCursor 获取栅格图层像素值
  20. CPU硬件辅助虚拟化技术

热门文章

  1. 利用拉格朗日乘子法从最优化问题中推导出KKT条件
  2. JAVA流程控制(查漏补缺)
  3. 用Nodemailer发个邮件不算难?
  4. .net core 序列日志Serilog
  5. Python学习的第四次总结
  6. journalctl查看内核/应用日志
  7. 无锡哲讯谈饲料加工行业ERP的功能
  8. linux 下彻底删除MySQL
  9. MySQL---MGR保姆版
  10. springboot启动日志:Multiple Spring Data modules found, entering strict repository configuration mode