Example #1
0
        BackgroundWorker woker;//后台线程管理者

        public StartPage()
        {
            string conStr = (string)Application.Current.FindResource("PrivateConnString");

            con = new OleDbConnection(conStr);
            try
            {
                con.Open();
                if (con.State == ConnectionState.Open)
                {
                    OleDbCommand     cmd = new OleDbCommand("select * from tb_lhf_measure where saveindex is not null", con);
                    DataSet          set = new DataSet();
                    OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
                    adp.Fill(set);
                    dt_measure = set.Tables[0];     //获取参数配置表格
                    strInsert  = ConstructString(); //构建插入字符串

                    var re1 = from h in dt_measure.AsEnumerable()
                              where h.Field <string>("name") == "pH"
                              select Convert.ToInt32(h.Field <object>("saveindex"));

                    foreach (int d in re1)
                    {
                        pH_saveindex = d;
                    }

                    var re2 = from h in dt_measure.AsEnumerable()
                              where h.Field <string>("name") == "电导率"
                              select Convert.ToInt32(h.Field <object>("saveindex"));

                    foreach (int d in re2)
                    {
                        DDL_saveindex = d;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //读取电子表格
            dt_property = OperateExcel.ReadExcel("系统用溶解度表.xlsx");
            InitializeComponent();//初始化组建
            /// 订阅事件
            UpdateUI += new UpdateUIHandler(mainWnd.DoWork);
            UpdateUI += new UpdateUIHandler(onLineStatic.BeginThread);
            //定时器设置
            timer       = new DispatcherTimer();
            timer.Tick += new EventHandler(ProvideData);
            timer.Tick += new EventHandler(DoWork);


            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Start();

            woker = new BackgroundWorker();//后台更新UI线程

            woker.DoWork += ComputeData;
        }