标签:inf red nta 控件 软件 load obj closed splay
情景:控件放在UI主线程中,实际改变控件值是在其他线程中,这是软件报错:不是创建该控件的线程访问控件
解决办法:
1、使用 delegate 和 Invoke:
1 private void button2_Click(object sender, EventArgs e) 2 { 3 Thread thr = new Thread(ThreadWork); 4 thr.Start(); 5 } 6 7 private void ThreadWork() 8 { 9 if (label2.InvokeRequired) 10 { 11 Action<string> act = (x) => { label2.Text = x; }; 12 label2.Invoke(act, "线程改变lab值"); 13 } 14 else 15 { 16 label2.Text = ""; 17 } 18 }
标签:inf red nta 控件 软件 load obj closed splay
原文地址:https://www.cnblogs.com/shayBlogs/p/14926566.html