遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

添加设备轮询操作

private IFacilityService facilitySrvA = ServiceLocator.Get<IFacilityService>();
private IFacilityService facilitySrvB = ServiceLocator.Get<IFacilityService>();

//需要生成两个代理类实体,不然同一个代理类实体的,两次调用会是按串行化方式进行

var timer1 = new System.Timers.Timer();
timer1.Interval = 100;
timer1.Enabled = false;
timer1.Elapsed += (s, e) =>
{
timer1.Enabled = false;
var t = facilitySrvA.GetStatus("ZD001");
Console.WriteLine("GetStatus:" + t +","+ DateTime.Now.ToString());
timer1.Enabled = true;
};
timer1.Start();

var timer2 = new System.Timers.Timer();
timer2.Interval = 500;
timer2.Enabled = false;
timer2.Elapsed += (s, e) =>
{
timer2.Enabled = false;
Console.WriteLine("触发了:SetIO");
var t = facilitySrvB.SetIO("ZD001", 12, 1);
Console.WriteLine("SetIO:" + t +","+ DateTime.Now.ToString());
timer2.Enabled = true;
};
timer2.Start();

 

轮询时间需要长点,开始可以设置2秒左右,以减少cpu占用

 

posted on 2016-09-19 10:08  遗忘海岸  阅读(244)  评论(0编辑  收藏  举报