在不是在其上创建线程的线程上访问控件 [英] Control accessed on a thread other than the thread it was created on

查看:68
本文介绍了在不是在其上创建线程的线程上访问控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之:我想加载表单,然后使用Background WorkerDatabase获取数据并设置一些组合框的数据源.
DoWork事件中,我获取数据,在RunWorkerCompleted事件中,我设置了数据源.问题是跨线程问题.我该怎么办才能解决这个问题?

In brief: I want to load my form, then using a Background Worker fetch data from Database and set the DataSource of some comboboxes.
In DoWork event I fetch data, and in RunWorkerCompleted event I set the datasources. The problem is cross-threading issues. What can I do to resolve this?

我不明白为什么设置DisplayMember可以,但是在下一行中,设置ValueMember会引发异常

推荐答案

我认为您倒想了. DoWork应该为FetchData,而DoWorkCompleted应该为BindComboBoxes.

I think you got it backwards. The DoWork should be FetchData and DoWorkCompleted should be BindComboBoxes.

这篇关于在不是在其上创建线程的线程上访问控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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