C# 线程应用

//以委托的方式创建线程
        private delegate void GridControl_DataBinder(DataTable DT);
        private void GridControl_DataBinderMothod(DataTable DT)
        {
            DevExpress.Data.CurrencyDataController.DisableThreadingProblemsDetection = true;

            if (this.gridControl1.InvokeRequired)
            {
                try
                {
                    GridControl_DataBinder del = new GridControl_DataBinder(GridControl_DataBinderMothod);
                    this.Invoke(del, new object[] { DT });
                }
                catch { }
            }
            else
            {
                gridControl1.DataSource = DT;
               }
        }

 //线程
        protected void thod()
        {
            Thread th = new Thread(gridControl_DataBinder_Thread);
            th.Start();
        }

        private void gridControl_DataBinder_Thread(object obj)
        {
            //数据绑定
            YaoPin_Bander();

        }

       //得到数据
        protected void YaoPin_Bander()
        {

            string yaopinSN = "";
            StringBuilder sbWhere=new StringBuilder ("1=1");
            if (Edit_SN.EditValue != null)
            {
              
                yaopinSN = Edit_SN.EditValue.ToString().Trim();
                sbWhere.Append(" and RY_SN='" + yaopinSN + "'");
            }
            BLL.Room_YaoPin bllYp = new BLL.Room_YaoPin();
            DataTable db = bllYp.GetList(sbWhere.ToString() + " order by id asc").Tables[0];// RY_AddTime desc,
            if (db.Rows.Count > 0)
            {
                  GridControl_DataBinderMothod(db);
                   // gridControl1.DataSource = db;
             }

}

你可能感兴趣的:(thread,object,String,C#,null)