Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 如何访问表单';是从另一个线程进行控制吗?_Multithreading_Forms_Visual C++_Variable Declaration - Fatal编程技术网

Multithreading 如何访问表单';是从另一个线程进行控制吗?

Multithreading 如何访问表单';是从另一个线程进行控制吗?,multithreading,forms,visual-c++,variable-declaration,Multithreading,Forms,Visual C++,Variable Declaration,使用VC++2010 我想从另一个线程中的类访问窗体控件。。也无法找到最好的(或任何)方法来实现这一点。如何传递表单实例的引用?我使用createthread()而不是托管版本,希望使我的应用程序与XP兼容 我曾尝试通过lpParameter传递结构中的引用和其他值,但似乎不知道如何正确声明引用 ref class SZClass { private: FMain ^bound_form; int server_port; public:

使用VC++2010

我想从另一个线程中的类访问窗体控件。。也无法找到最好的(或任何)方法来实现这一点。如何传递表单实例的引用?我使用createthread()而不是托管版本,希望使我的应用程序与XP兼容

我曾尝试通过lpParameter传递结构中的引用和其他值,但似乎不知道如何正确声明引用

ref class SZClass {
    private:
        FMain ^bound_form;
        int server_port;
    public:
        void BindForm(FMain ^bf);
        void Initialize(int sp)
}

struct param_data {
    public:
        FMain ^form_tobind;
        int port_num;
}
你给了我错误:

error C2143: syntax error : missing ';' before '^'
FMain是我的表单类的名称,我已经设置了一个委托方法,以使其具有多线程安全性:

public:
    FMain(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

    void FMain::PrintConsole(std::string mzg) {
        String ^Smzg = marshal_as<String^>(mzg);
        if (this->textBox1->InvokeRequired) {
            SetTextDelegate^ d =  gcnew SetTextDelegate(this, &FMain::PrintConsole);
            this->Invoke(d, gcnew array<Object^> { Smzg });
        } else {
            textBox1->Text += Smzg;
            textBox1->SelectionStart = textBox1->TextLength;
        }
    }
公共:
主要(无效)
{
初始化组件();
//
//TODO:在此处添加构造函数代码
//
}
void FMain::PrintConsole(std::string mzg){
字符串^Smzg=封送(mzg);
如果(此->文本框1->需要调用){
SetTextDelegate ^d=gcnew SetTextDelegate(此,&FMain::PrintConsole);
这->调用(d,gcnewarray{Smzg});
}否则{
textBox1->Text+=Smzg;
textBox1->SelectionStart=textBox1->TextLength;
}
}
如何声明对我的表单的引用?
或者有更简单或更好的方法吗?

我不知道您使用的是什么表单库,但您的问题的一般经验法则是“不要”


除非您有一个特殊的GUI库,否则Windows UI是线程亲合的。所有对UI元素的访问都应该通过UI的仿射线程完成。应该通过将更新请求封送到关联上下文来完成从未定义的执行上下文操纵UI状态。它不应该直接完成。

好吧,我的表单类中已经有一个委托函数来确保它的安全性,我只是不知道如何建立从新线程到表单的连接。。请参阅上面的更新。这只是典型的Smzg问题,在标题之间存在循环依赖关系。FMain类需要了解SZClass,SZClass需要了解FMain。必须在C++和.h和.cp文件之间执行向前声明和分割声明和定义的C++舞蹈。顺便说一句,你需要有人检查你的代码,问问团队成员或朋友。我有一个.h和.cpp的课程,这还不够吗?我的形式课也必须这样做吗?我应该把哪一项包括在内?当我列出三件事而你做了其中两件事时,这是不够的。谷歌“c++转发声明”,第一次点击是好的。当你不熟悉C++语言时,在C语言中写这个。我在Borland上学习C++ 15,最近在VC++上重新学习它,我没有C语言的经验,不想尝试…我只是想澄清一下我现在想把我的fmain.h分为fmain.h和fmain.cpp。。但我现在有一些设计师的错误,我正试图弄清楚。