情况是这样的:
  C/S结构下,client端frmLogin建立socket与server端建立连接后,
  Thread thread=new Thread (new ThreadStart (receive));
  thread.Start ();  private void receive()中当收到server端通过验证的信息后,  Form1 mainform = new Form1();
  mainform.Show();  但程序运行到这里后新的mainform里无法正常显示.
  如果在frmLogin下直接生成mainform并Show(),是正常的,所以觉得是多线程导致的问题,只是不知道该如何具体解决.
  请高手指点   

解决方案 »

  1.   

    不要在工作者线程里面创建窗体,你应该先行创建好主窗体并且隐藏起来,然后在工作都线程里面Invoke主窗体的Show()方法来显示主窗体。
      

  2.   

    如此在主窗体manform的main()中加入
    [STAThread]
    static void Main() 
    {
        Form1 f1 = new Form1();
        f1.Hide();
        Login f2= new Login();
        f2.Show();
        Application.Run();
    }
    然后在f2中无法调用f1.invoke()是否在实例化2个form或者在调用方法时需要其他代码控制?
      

  3.   

    现在就不知道2个FORM间该如何实例化并取得INVOKE去委托。...
      

  4.   

    public class Form1
    {         
            public class WatchConst
    {
    public static Form1 f1;
    public static Form2 f2;
    }        [STAThread]
    static void Main() 
    {
    WatchConst.f1 = new Form1();
    WatchConst.f1.Show();
    WatchConst.f2 = new Form2();
    WatchConst.f2.Hide(); Application.Run();
    }
            
           private void button1_Click(object sender, System.EventArgs e)
    {
                               Thread thread=new Thread (new ThreadStart (receive));
    thread.Start ();
    }       private void receive()
                      {
                        //想在这里显示WatchConst.f2.Show()
                        //应该如何代码?
                      }