如何使用控制->;调用()? 我不确定使用.NET、C++和Windows窗体的控件->调用()的正确用法。

如何使用控制->;调用()? 我不确定使用.NET、C++和Windows窗体的控件->调用()的正确用法。,.net,winforms,delegates,c++-cli,.net,Winforms,Delegates,C++ Cli,例如,使用这种方法: System::Void UI::setStatusText(System::String^ text) { if (this->InvokeRequired) { SetTextDelegate^ d = gcnew SetTextDelegate(this, &UI::setStatusText); statusLabel->Invoke(d, gcnew array<Object^> { text

例如,使用这种方法:

System::Void UI::setStatusText(System::String^ text) {
    if (this->InvokeRequired) {
        SetTextDelegate^ d = gcnew SetTextDelegate(this, &UI::setStatusText);
        statusLabel->Invoke(d, gcnew array<Object^> { text }); // <-- System.ExecutionEngineException
    } else
        statusLabel->Text = text;
}
但我经常在标记行中看到System.ExecutionEngineeException

这个代码怎么了

谢谢, 马丁


编辑:visual studio表示mscorlib.dll中存在System.ExecutionEngineeException类型的非托管异常,绿色调试箭头指向标记行。这是堆栈跟踪:。但是我怎样才能得到内部异常呢?或者,如果这不是由这些代码行引起的,我还能做些什么来找出错误

代理代码似乎是正确的。但我不明白你在干什么。您正在创建一个委托,该委托创建相同的函数setStatusText!!我想你是想做这样的事情:

delegate void SetTextDelegate();

System::Void UI::setStatusText(System::String^ text)
{
  statusLabel->Text = text
}

System::Void UI::ANOTHER_FUNCTION(System::String^ text)
{   
   SetTextDelegate^ d = gcnew SetTextDelegate(this, &UI::setStatusText);
   statusLabel->Invoke(d, gcnew array<Object^> { text });
}
delegate void SetTextDelegate();
System::Void UI::setStatusText(系统::字符串^text)
{
状态标签->文本=文本
}
System::Void UI::另一个函数(System::String^text)
{   
SetTextDelegate ^d=gcnew SetTextDelegate(this,&UI::setStatusText);
statusLabel->Invoke(d,gcnew数组{text});
}

异常信息是什么?它有内部异常吗?如果是,那是什么?它不太可能与此代码有任何关系。FEEE通常在托管堆损坏时生成。这是由以前运行的代码完成的,通常是本机代码。
delegate void SetTextDelegate();

System::Void UI::setStatusText(System::String^ text)
{
  statusLabel->Text = text
}

System::Void UI::ANOTHER_FUNCTION(System::String^ text)
{   
   SetTextDelegate^ d = gcnew SetTextDelegate(this, &UI::setStatusText);
   statusLabel->Invoke(d, gcnew array<Object^> { text });
}