You need to run Invoke on the control that is being called to from the
thread. If this is your own control, you can simply do it from the method
itself:
public class MyControl: Control {
...
delegate void MyMethodDelegat e(string param);
public void MyMethod(string param) {
// This method supposedly access properties in the control,
// so calls should be marshalled onto the GUI thread.
if (InvokeRequired ) {
Invoke(new MyMethodDelegat e(MyMethod), param);
return;
}
// Now do whatever the method is really supposed to do
...
}
...
}
If it's not your control, it's also possible to call Invoke from the
outside. Both the InvokeRequired property and the Invoke method are
public, so you can call them from the outside. In your class, if I
understand your sample code correctly (which seems to be nonsense because
you have the field named "updateEventQue ueListView", but then you suddenly
call a method called the same):
delegate void UpdateListViewD elegate(ListVie wItem item);
if (updateEventQue ueListView.Invo keRequired) {
updateEventQueu eListView.Invok e(new UpdateListViewD elegate(
updateEventQueu eListView.Updat eListView), item);
}
.... or something like that - I'm guessing at a lot of your types and
methods here.
Oliver Sturm
--
Expert programming and consulting services available
See
http://www.sturmnet.org (try /blog as well)