Multi Threading in Framework 2.0 Beta

  • Thread starter Thread starter Richard
  • Start date Start date
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
 
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
 
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;
}
}
 
Back
Top