开发者

User Control creating and hiding a form Threading issues

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??


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜