从 cli 中的线程(在单击按钮时创建)更新主 GUI 中的文本框

Updating a textbox in main GUI from a thread (created on button click) in cli

我对基于 C# 的 C++/CLI 很陌生。我有一个主 GUI 窗体。

public ref class MyForm : public System::Windows::Forms::Form

单击发件人中的按钮后,我正在使用 CreateThread 创建一个线程。代码如下:

private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) 
{

HANDLE h1;

h1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread1,0, 0, &threadID1);

}

现在我的问题是我需要从线程更新 Myform 中的 TextBox。谁能告诉我如何在 cli 中执行此操作?

在这种情况下使用 .NET Thread^ 是安全的。在你的 thread1 方法中使用 Control::BeginInvokeControl::Invoke 就像提到的@AlexF。 Here 你有一个来自 C# 的例子。