为什么我的 winform 在我使用清除文本框并追加文本方法 "simultanly" 时冻结? (多线程)

Why does my mainform freeze when I use clear texbox and append text methods "simultanly" ? (multithreading)

我的主窗体上有一个文本框,另一个 class 中有一个线程 运行,它有时会通过使用 Texbox.AppendText("some text") 添加一些文本来更新同一个文本框。在我的主窗体上,我有一个清除按钮,当用户使用 Texbox.Clear() 按下此按钮时,它会清除文本框。 但我注意到,有时,当用户在另一个线程正在更新同一个文本框的同时按下这个清除按钮时,我的 IHM 会冻结几秒钟,然后我可以再次使用它。 我使用了线程安全的调用方法,就像 MSDN doc 中所说的那样,但我不明白为什么它不能正常工作。这是我的代码:

// 在我的主窗体 MainWindow

public static MainWindow GetInstance()
{
    if (_IHM_Main == null)
    {
        _IHM_Main = new MainWindow();
    }
    return _IHM_Main;
}   

public delegate void SafeCallDelegate(System.Windows.Forms.TextBox textBox, String texte);
public static void AppendText(System.Windows.Forms.TextBox textBox, String texte)
{
    if (textBox.InvokeRequired)
    {
        var d = new SafeCallDelegate(AppendText);
        textBox.Invoke(d, new object[] { texte });
        textBox.AppendText(texte);
    }
    else 
        textBox.AppendText(texte);
}


private void btn_Clear_Click(object sender, EventArgs e)
{
    if (textBox3.InvokeRequired)
    {
        MainWindow.GetInstance().BeginInvoke(new MethodInvoker(() => MainWindow.GetInstance().textBox3.Clear()));
    }
    else
        textBox3.Clear();
}

// 在我的 Class1.cs 中线程是 运行

private delegate void ChangeTextBox(System.Windows.Forms.TextBox textbox, String texte);
private void UpdateTextboxRandomly()
{
    MainWindow.GetInstance().Invoke(new ChangeTextBox(MainWindow.AppendText), MainWindow.GetInstance().textBox3, "adding some text");
}

最后我通过使用(使用相同的代码)RichTextBox 而不是 TextBox 解决了我的问题。 似乎TextBox不适合那个串行接收任务