Linq to Sql 结果导致组合框异步
我正在开发一个 winform 应用程序,并将在数据库中发出请求并异步填充我的组合框,但遇到访问控制问题,因为它们来自另一个线程,这是代码。
this.backWorker.DoWork + = delegate
{
comboBoxUsers.DataSource = repositoryUser.SelectAll();
comboBoxUsers.ValueMember = "UserId";
comboBoxUsers.DisplayMember = "Name";
};
backWorker.RunWorkerAsync ();
我正在研究 envoke 但我在实现它时遇到了困难, 我需要做的就是让 DoWork 事件可见进度条并选择执行此操作。
I'm developing a winform application and would make a request in the database and populate my combobox asynchronously but am having problem of access control because they come from another thread, here's the code.
this.backWorker.DoWork + = delegate
{
comboBoxUsers.DataSource = repositoryUser.SelectAll();
comboBoxUsers.ValueMember = "UserId";
comboBoxUsers.DisplayMember = "Name";
};
backWorker.RunWorkerAsync ();
I am studying about envoke but I'm having trouble getting to implement this,
I needed to do was leave the DoWork event visible progress bar and select to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅在BackgroundWorker上查询您的存储库并通过ProgressChangedEvenHandler将结果返回到UI
Only query your repository on the BackgroundWorker and return the results through the ProgressChangedEvenHandler to the UI
你的委托应该这样写:
有关如何从另一个线程访问 UI 线程的 UI 控件的详细信息,请参阅此处:
从Backgroundworker DoWork访问窗口控制
该链接有一个明确的答案,这里有一个片段:
your delegate should be written like this:
for details on how to access UI controls of the UI Thread from another thread see here:
Access windows control from Backgroundworker DoWork
there is a clear answer at that link, here a snippet: