1.如我们在使用winform点击按钮获取大量数据的时候界面会假死(卡主),所以我们使用多线程分开处理,代码如下
private void button1_Click(object sender, EventArgs e)
{
TestData();
}
public void CallToChildThread()
{
var a = 0;
for (int i = 0; i < 2147483647; i++)
{
a = i;
}
this.Invoke(new Action(() =>
{
textBox2.Text = Convert.ToString(a);
}));
}
public void TestData() {
ThreadStart childref = new ThreadStart(CallToChildThread);
Thread th = Thread.CurrentThread;
Thread childThread = new Thread(childref);
childThread.Start();
}