日期:2014-05-18 浏览次数:20956 次
public class 线程操作类
{
  public object 设备信息;
  public void 读取数据方法()
  {
  //读取并写入数据库
  }
}
timer_Tick(object sender, EventArgs e)
{
     BackgroundWorker[] bgws = new BackgroundWorker[设备总数];
     线程操作类[] temps = new 线程操作类[设备总数];
    for(int i=0;i<设备总数,i++){
    //实例化线程和线程操作类
    bgws[i] = new BackgroundWorker();
    temps[i] = new 线程操作类();
   //设置线程工作的方法
    bgws[i].DoWork += new DoWorkEventHandler(temps[i].读取数据方法);
    //启用线程
    bgws[i].RunWorkerAsync()
}
}
            System.Timers.Timer timer = new System.Timers.Timer(5000);
            for (int i = 0; i < 设备总数; i++)
            {
                int j = i;//必须再给一个 变量,否则后面的委托将用i的最后一个值
                timer.Elapsed += delegate 
                {
                    //这里写对应设备的处理方法
                    temps[j].读取数据方法
                };
            }
            timer.Start();