views:

8

answers:

1

I've got a control called ChatController, as a private member I have:

private frmChat m_chatWindow = null;

In ChatController's constructor I do:

m_chatWindow = new frmChat(strJobNumber, m_emailAddress);   

if (m_chatWindow.InvokeRequired)
    m_chatWindow.Invoke(new MethodInvoker(delegate { m_chatWindow.Hide(); }));
else
    m_chatWindow.Hide();

But I can't hide m_chatWindow no matter what I do, it randomly thinks InvokeRequired is true or false, and an error is thrown saying "cross-thread blah blah blah..".

This is already existing and the only thing I have changed is m_chatWindow.Show(this) to m_chatWindow.Hide().

Any Ideas how I can resolve this??

+1  A: 

After calling the constructor of your form, it won't show up. So there is no need to hide it.

If you don't wan't to display it right after creation, just throw away the whole if-else part. Then later in your code where you like to show your m_chatWindow just call it with the already known Show() function.

Oliver