1

我有两种形式。我想同时启动它们。在主程序中,我遵循 Md Kamruzzaman Pallob 的建议。以下代码是更新版本,但还是不行。

错误是错误 C3350:'System::Threading::ThreadStart':委托构造函数需要 1 个参数

   #include "stdafx.h"
  #include "Form1.h"
  #include "Form3.h"
   using namespace MySearch;
   using namespace System;
   using namespace System::Threading;



 public ref class ThreadX{
 public: ThreadX(){}
 public: static void func1()
{
    Application::Run(gcnew Form1());
}

public: static void func2()
{
    Application::Run(gcnew Form3());
}


};


[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); 

// Create the main window and run it


    ThreadX^ o1 = gcnew ThreadX();
    ThreadX^ o2 = gcnew ThreadX();

    Thread^ th = gcnew Thread(gcnew ThreadStart(o1, &ThreadX::func1));
    Thread^ th1 = gcnew Thread(gcnew ThreadStart(o2, &ThreadX::func2));
    th->Start();
    th1->Start();



return 0;

}

4

3 回答 3

1

你为什么不像下面那样做一个 form1 加载事件?:

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
         Form2^ form2 = gcnew Form2;
         form2->Show();
     }

然后每次打开 Form1,Form2 也会打开。它似乎对我有用。

于 2012-05-03T00:34:31.700 回答
0

您可以通过使用线程来做到这一点。我很抱歉,因为我不太了解 C++。但我可以用c#给你解决方案

 public static void func1()
    {
        Application.Run(new Form1());
    }

   public static void func2()
    {
        Application.Run(new Form2());
    }

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Thread th = new Thread(func1);
        Thread th1 = new Thread(func2);
        th.Start();
        th1.Start();
    }
于 2012-04-30T01:01:23.417 回答
0

尝试 :

Thread^ th = gcnew Thread(gcnew ThreadStart( &ThreadX::func1 ) );
Thread^ th1 = gcnew Thread(gcnew ThreadStart( &ThreadX::func2 ) );

请参阅http://msdn.microsoft.com/en-us/library/system.threading.threadstart.aspx

于 2012-12-10T00:47:49.563 回答