Thread Question

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi,
To make my form responsible, I use a 2nd thread to do a process.
If I try to get the text of a combo box on a form from within the thread, I get cross thread... exception.
That is normal, because combo box on the form is for another thread.
So I store the value of ComboBox.Text into a string variable and use that string in my thread and it works.

One thing is strange here:
When I try to get the checked value of radio button directly from within thread it works fine and I receive no exception.

> It means that I should continue to do what I do? OR it just works and is not recommended and I should the same as I do for combo box for radio button also?
(This applies to some other controls also)

Thanks :)
 
I'm not particularly experienced with multi-threading, but my understanding is that one should not interact directly with the UI from secondary threads. Caching values before invoking the thread or obtaining the values via the Invoke method would probably be the way to go.
 
I haven't had any problems like that either. Are you monitoring the combobox in the thread for a change? and when you select something else, this is when you get the error?

Before you start the thread. you may want to try and set "isBackground = true" for that thread.
 
Back
Top