views:

57

answers:

3

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?

A: 

you need to invoke your label updates back to the main thread

see Dispatcher.Invoke

Mike
Note that he is in WinForm not a WPF based one.
John
You're right. I missed that. I've been stuck in Silverlight/WPF mode for a while now :)
Mike
+4  A: 

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.

John