private delegate void InvokeHandler();
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
Thread thread = new Thread(new ThreadStart(delegate
{
while (true)
{
Thread.Sleep(1000);
//MessageBox.Show("..");
this.Invoke(new InvokeHandler(delegate()
{
dataGridViewX1.DataSource = dClass.GetDataTable(sql);
}));
int a = this.dataGridViewX1.DisplayedRowCount(false);
for(int i=0;i<this.dataGridViewX1.Rows.Count/a+1;i++)
{
Thread.Sleep(int.Parse(time));
if (i * a < this.dataGridViewX1.Rows.Count)
{
dataGridViewX1.FirstDisplayedScrollingRowIndex = i * a;
}
}
Thread.Sleep(int.Parse(time));
}
}));
thread.IsBackground = true;
thread.Start();
}
C#线程访问UI控件时出现假死
最新推荐文章于 2024-04-19 13:52:31 发布