RaiseEvent 触发“Debugger.Runtime.CrossThreadMessagingException”
我在 VB.NET 中有一个类,它有一个返回数字的方法(称为 CurrentValue)。班级还会引发一个事件来表明数字已更改。在表单的事件处理程序中,我使用公开的方法更新文本框。
有点像这样:
Public WithEvents MyClass as New CustomClass
Private Sub MyClass_DataChanged() Handles MyClass.DataChanged
Text1.Text = MyClass.CurrentValue
End Sub
当我运行这个时,我收到“Debugger.Runtime.CrossThreadMessagingException”错误。这可能是什么?我正在以包含文本框的相同形式实例化 MyClass。
我还可以毫无问题地设置 MyClass 对象的属性。
I have a class in VB.NET that has a method (called CurrentValue) that returns a number. There is also an event that the class raises to indicate the number has changed. In the event handler on my form, I update a textbox using the exposed method.
Sort of like this:
Public WithEvents MyClass as New CustomClass
Private Sub MyClass_DataChanged() Handles MyClass.DataChanged
Text1.Text = MyClass.CurrentValue
End Sub
When I run this I get a "Debugger.Runtime.CrossThreadMessagingException" error. What could be doing this? I am instantiating MyClass in the same form that contains the textbox.
I can also set properties of the MyClass object without any trouble.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这就是我所做的:
在表单中我有这个来处理事件:
这似乎有效。谢谢你的建议。
OK, here's what I did:
In the form I have this to handle the event:
This seems to work. Thanks for the suggestion.