由于GridControl加载的数据量比较大,为了不出现假死的想象,需要先加载UI界面再加载数据
具体做法:
private void TableListUserControl_Load ( object sender ,EventArgs e ) { //加载线程 System.Threading.Thread thread = new System.Threading.Thread( new System.Threading.ThreadStart( this.query ) ); thread.Start( ); }
void query ( ) { bool ok = this.Do( ); this.BeginInvoke( new System.Threading.ThreadStart( delegate ( ) { if ( ok ) { //界面加载完毕 读取数据并且绑定控件 GenerateCodeBll.Bll.TableListUserControlBll _bll = new GenerateCodeBll.Bll.TableListUserControlBll( ); DataTable da = _bll.GetDataTable( ); da.Columns.Add( "check" ,typeof( System.Boolean ) ); gridControl1.DataSource = da; } } ) ); }
另一个我自己的想法:可以加载UI和查询数据分两个线程同时进行,等界面加载好之后再绑定数据源到控件。bool Do ( ) { //等待1s再加载数据 System.Threading.Thread.Sleep( 1000 ); return true; }