线程间操作无效:从不是创建控件“textBox1”的线程访问它
问题代码:
public void test(object source, ElapsedEventArgs e)
{
//实例化BLL层对应界面
QRcodeBLL qucode = new QRcodeBLL();
//501考场剩余座位
StudentBindPaperTypeEntity StudentBindPaperType = new StudentBindPaperTypeEntity();
StudentBindPaperType.IP = textBox2.Text.Trim();
DataTable dt = qucode.SelectByIP(StudentBindPaperType);
//511考场剩余座位
StudentBindPaperTypeEntity StudentBindPaperType1 = new StudentBindPaperTypeEntity();
StudentBindPaperType.IP = textBox3.Text.Trim();
DataTable table = qucode.SelectByIP(StudentBindPaperType);
textBox1.Text = "501剩余座位数:" + (200 - Convert.ToInt32(dt.Rows[0][0])) + Environment.NewLine
+ "511剩余座位数:" + (

这篇博客探讨了在编程中遇到的线程间操作无效的问题,详细介绍了如何从非创建线程访问控件‘textBox1’时引发的错误。文章通过提供问题代码示例,展示了两种解决方法,包括在窗体构造函数中添加控件同步和使用委托来正确地跨线程操作控件,从而避免此类异常。
2517

被折叠的 条评论
为什么被折叠?



