views:

112

answers:

1

Hey Guys,

I've got a cross thread invoke going on, and the invoke works fine, however I have found that all subsequent function calls need to be invoked aswell, otherwise it throws exceptions, how do I go about either modifiying my invoke command, or through some other solution, fix this?

This is my current invoker:

foreach (chat_window oc in open_chats)
{
    if (oc.Name == friend)
    {
        string updmsg = msg.Substring(msg.IndexOf('\n')).Trim();
        string[] argNames = new string[2];
        argNames[0] = friend;
        argNames[1] = updmsg;
        Type t = oc.GetType();

        t.InvokeMember("updateChat", 
            System.Reflection.BindingFlags.InvokeMethod, null, oc, argNames);
        }
}

Thanks in advance, Psy

+1  A: 

I assmue that chat_window is some WinForms object derived from Control?

If so then you probably want to use Control.Invoke/Control.BeginInvoke in order to marshall the call back to the UI thread.

oc.Invoke(oc.updateChat, argNames);
Iain