Invoking control from different thread

  • Thread starter Thread starter david s
  • Start date Start date
D

david s

I've got a combobox that I am getting updated data for in real time and
need to clear out the values and reload it with the new data. I keep
getting an error that I can't access the control because it was created
from a different thread. I've been trying to figure out how to do this
using Invoke/Delegates, but am greatly confused and stuck. Any help
would be greatly appreciated. Thanks!


All I need is this, but how do I do it using an invoke/delegates?!? :

comboBox.Items.Clear();
for (int i = 0; i < count; i++)
comboBox.Items.Add(i);

Thanks again!

David
 
david s said:
I've got a combobox that I am getting updated data for in real time and
need to clear out the values and reload it with the new data. I keep
getting an error that I can't access the control because it was created
from a different thread. I've been trying to figure out how to do this
using Invoke/Delegates, but am greatly confused and stuck. Any help
would be greatly appreciated. Thanks!


All I need is this, but how do I do it using an invoke/delegates?!? :

comboBox.Items.Clear();
for (int i = 0; i < count; i++)
comboBox.Items.Add(i);

Thanks again!

David

Something like this?

delegate void MyDel(int max);

void Foo()
{
MyDel d = delegate(int max)
{
comboBox.Items.Clear();
for (int i = 0; i < max; i++)
comboBox.Items.Add(i);
};
comboBox.BeginInvoke(d, 42);
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 
Back
Top