关于c#:47c-新建线程Thread线程内与操作窗体控件

3次阅读

共计 879 个字符,预计需要花费 3 分钟才能阅读完成。

Thread t3 = new Thread(() =>
            {Console.WriteLine("a2....");
                WriteLog("ComListForm.t3.begin..");
                RefreshListFormDb();});
            t3.IsBackground = true;
            t3.Start();

RefreshListFormDb() 须要更新 datagridView:

List<ComPhoneBean> list = rv_list.Value;
                        MethodInvoker mi = new MethodInvoker(() =>
                        {WriteLog("ComListForm.RefreshListFormDb....5.");
                            UpdateDataGrid(list);
                        });
                        
                        this.BeginInvoke(mi);

UpdateDataGrid 这个办法更新 Datagridview 的内容:

private void UpdateDataGrid(List<ComPhoneBean> list)
        {WriteLog("ComListForm.UpdateDataGrid....1.");
            if (list==null || list.Count == 0)
            {WriteLog("ComListForm.UpdateDataGrid....2.");
                return;
            }
            WriteLog("ComListForm.UpdateDataGrid....3.");
            this.dataGridView1.Rows.Clear();
            WriteLog("ComListForm.UpdateDataGrid....4.");
            int index = 0;
            foreach(ComPhoneBean bean in list)
            {
                index++;
                this.dataGridView1.Rows.Add(new string[] {""+ index, bean.ComPort, bean.Phone,"" + bean.SignalIntensity});
            }
            WriteLog("ComListForm.UpdateDataGrid....5.");
        }
正文完
 0