开启一个新线程;
在这个线程中,进行任务排队。
任务1完成后,等待延时200ms,再运行任务2
private void Timer1_Tick(object sender, EventArgs e)
{
//throw new NotImplementedException();
Task.Run(() =>
{
this.Invoke( new Action( () =>
{
listBox1.Items.Add("进中断"+DateTime.Now.ToString() + "\r\n");
}));
//RS485.Set_io(7);//ok
//RS485.Rest_io(7);//ok
if (i > 8) i = 0;
RS485.Set_io(i++);//ok
this.Invoke(new Action(() =>
{
listBox1.Items.Add("第1次输出" + DateTime.Now.ToString() + "\r\n");
}));
Thread.Sleep(200);
RS485.Rest_io((ushort)(i - 2));//ok
this.Invoke(new Action(() =>
{
listBox1.Items.Add("第2次输出" + DateTime.Now.ToString() + "\r\n");
}));
Thread.Sleep(200);
//RS485.Read_io_out(0,8);//ok
RS485.Read_io_in(0, 8);//ok
this.Invoke(new Action(() =>
{
listBox1.Items.Add("第3次输出" + DateTime.Now.ToString() + "\r\n");
}));
//RS485.Read_io_Reg(0,4);//
//RS485.Read_io_Regs(0, 6);//
Thread.Sleep(200);
});
}