Я выяснил, как сделать потокобезопасный вызов с того же сайта, о котором я говорил (https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-make-thread-safe-calls-to-windows-forms-controls).) В правом верхнем углу страницы есть небольшой символ (</>
), который меняет примеры кода на один из трех вариантов: C #, VB или C ++.
Вот код, который я использовал для настройки нового потока и запуска безопасного для потока вызова на метке формы в потоке пользовательского интерфейса из нового потока:
private:
Thread^ Thread1;
private: System::Void WindowTVVmixSelect_Click(System::Object^ sender, System::EventArgs^ e) {
if (GUIEvent == false) {
GUIEvent = true;
Console::WriteLine("Window TV Vmix Select");
StatusOutput->Text = "Please Wait";
MyForm::Refresh();
//Creation of new thread.
this->Thread1 =
gcnew Thread(gcnew ThreadStart(this, &MyForm::ThreadWindowTVVmixSelect));
this->Thread1->Start();
}
}
private:
void ThreadWindowTVVmixSelect()
{
Sleep(3000);
//SetTextWindowHDMIStatus("Vmix");
SetTextStatusOutput("");
GUIEvent = false;
}
delegate void StringArgReturningVoidDelegate(String^ text);
//Sets the status label in the form
private:
void SetTextStatusOutput(String^ text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this->StatusOutput->InvokeRequired)
{
StringArgReturningVoidDelegate^ d =
gcnew StringArgReturningVoidDelegate(this, &MyForm::SetTextStatusOutput);
this->Invoke(d, gcnew array<Object^> { text });
}
else
{
this->StatusOutput->Text = text;
}
}
Надеюсь, это поможет всем, кто хочет обновить форму C ++ CLR из другого потока.