Multi Threading in Framework 2.0 Beta

R

Richard

Hi,
I have a form with some ComboBox controls on it. I am populating it on a new
thread in Framework 1.1. But it does't work with Framework 2.0 Beta. It says
"Cross-thread operation not valid".
What is the best way to do it in Framework 2.0.

Richard
 
J

Jon Skeet [C# MVP]

Richard said:
I have a form with some ComboBox controls on it. I am populating it on a new
thread in Framework 1.1.

That's a bad idea even in 1.1. Just because you happen to be getting
away with it at the moment doesn't mean it won't break at any second.
But it does't work with Framework 2.0 Beta. It says
"Cross-thread operation not valid".
What is the best way to do it in Framework 2.0.

See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml
 
L

Lloyd Dupont

the solution is to use thread safe method ;)
well if you wonder how to make it safe here is a 2.0 Winform sample:

delegate void InvokeDelegate();
class Form
{
public void SafeComboData(object[] source)
{
if(InvokeRequired)
BeginInvoke(new InvokeDelegate(delegate() {
DirectSetComboSource(source); }));
else
DirectSetComboSource(source);
}
void DirectSetComboSource(object[] source)
{
myComboBox.DataSource = source;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top