跨线程操作无效:控件"ddlCountry" [英] Cross-thread operation not valid: Control 'ddlCountry'

查看:68
本文介绍了跨线程操作无效:控件"ddlCountry"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跨线程操作无效:控制'ddlCountry'是从创建该线程的线程之外的其他线程访问的.

Cross-thread operation not valid: Control 'ddlCountry' accessed from a thread other than the thread it was created on.

尝试设置以下字符串时出现此错误.

I get this error when trying to set the below string.

strSendData = "RGRG"

strSendData = "RGSTR"

+ txtUserName.Text

+ txtUserName.Text

+ " |" + txtPassword.Text

+ "|" + txtPassword.Text

+ " |" + txtEmail.Text

+ "|" + txtEmail.Text

+ " |" + txtFName.Text

+ "|" + txtFName.Text

+ " |" + txtLName.Text

+ "|" + txtLName.Text

+ " |" + ddlCountry.SelectedValue

+ "|" + ddlCountry.SelectedValue

+ " |" + ddlState.SelectedValue;

ddlState做同样的事情.我想要做的就是获取值,而不是将ddlCountry或State设置为任何值.网上唯一的例子是设置ddl不获取其值的方法.为什么我只用ddl而不是字符串中的文本框也有问题.

谢谢

Thanks

推荐答案

您无法从创建控件的线程之外的其他线程访问控件

you cannot access control from other thread than one that created control.

在此处查看如何使用匿名委托进行工作

see here how you should work using anonymous delegate

http://www.galcho.com/Blog/PermaLink.aspx?guid=fd83be7a-30a6-4b0a-b8da-363​​26cf68b80

希望这会有所帮助


这篇关于跨线程操作无效:控件"ddlCountry"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆