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 MyMethodDelegate(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 MyMethodDelegate(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 "updateEventQueueListView", but then you suddenly
call a method called the same):
delegate void UpdateListViewDelegate(ListViewItem item);
if (updateEventQueueListView.InvokeRequired) {
updateEventQueueListView.Invoke(new UpdateListViewDelegate(
updateEventQueueListView.UpdateListView), 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)