本文介绍了避免跨线程调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好 我有一个带有gui的表单,只有一些列表框。 和一个处理传入数据的类。 i想要在接收数据时更新我的​​gui。 但是即使我在我的班级中创建了一个实例来处理 接收gui表单的数据如果我尝试直接更新gui我得到一个 交叉线程错误,试图从其他线程访问表单列表框 是创建它的那个。 因为调用gui update方法的方法是异步的。 如何我绕过这个,我已经尝试使用事件和代表获得 类,在接收数据时,触发事件然后将该事件挂钩到 gui so它会在事件发生时更新,但这仍然会导致同样的错误。 这一定是可能的吗? 解决方案 >我有一个带有gui的表单,只有一些列表框。 尝试将表单的CheckForIllegalCrossThreadCalls属性设置为false。或者看看这里: http:// msdn2.microsoft.com/en-us/library/ms171728.aspx 希望这会有所帮助, Mike - Microsoft Visual Basic MVP - 电子邮件: ED***@mvps.org WWW: Http://ryais.mvps.org/ 试试将表单的CheckForIllegalCrossThreadCalls属性设置为false。或者看看这里: http:// msdn2.microsoft.com/en-us/library/ms171728.aspx 希望这会有所帮助, 迈克 - Microsoft Visual Basic MVP - 电子邮件: ED***@mvps.org WWW: Http://EDais.mvps.org/ Hi guysI have a form with my gui on, just some list boxes.And a class that handles incoming data.i want to, on receiving data, update my gui.However even though i have an instance created in my class handling thereceiving data of the gui form if i try and update the gui directly i get across thread error, trying to access the form listbox from a thread otherthat the one it was created on.its because the method that called the gui update method is asynchronous.How do i get round this, i have tried using events and delegates getting theclass to, on receving data, fire an event and then hook that event to thegui so it updates on the event firing but this still causes the same error.This must be possible right? 解决方案Try setting the CheckForIllegalCrossThreadCalls property of your form to false. Alternatively have a look here: http://msdn2.microsoft.com/en-us/library/ms171728.aspxHope this helps,Mike- Microsoft Visual Basic MVP -E-Mail: ED***@mvps.orgWWW: Http://EDais.mvps.org/ Try setting the CheckForIllegalCrossThreadCalls property of your form to false. Alternatively have a look here: http://msdn2.microsoft.com/en-us/library/ms171728.aspx Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ 这篇关于避免跨线程调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 21:01
查看更多