如何异步更新winform? [英] How can I update a winform asynchronously?
问题描述
任何人都可以帮我吗?
您只能从创建的线程更新标签,以及您尝试从工作线程更新标签的外观。
查看方法 Control.BeginInvoke()并从那里拿走。还有其他方法,如 Control.EndInvoke 和 Control.Invoke 以及属性 Control.InvokeRequired ,这也将在此上下文中有所帮助。
I've got a winform, and a bluetooth connection with a lego nxt brick. Now I want to update the form every second to read sensors or the battery level. But if I start a new thread for that, there i a invalid thread operation exception when the thread wants to set the label text.
Can anyone help me?
You can update the label only from the thread that created it and by the looks of it you are trying to update it from the worker thread.
Have a look at the method Control.BeginInvoke() and take it from there. There are other methods like Control.EndInvoke and Control.Invoke and also the property Control.InvokeRequired, that will be helpful in this context as well.
这篇关于如何异步更新winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!