本文介绍了控制'richTextBox1'从c#创建的线程以外的线程访问c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们。我正在从richTextBox

hi friends. i'm retreiving data from the richTextBox


中检索数据。但是我得到了上面的错误。我可以解决这个问题吗

. but i got above error.how can i solve this

推荐答案

// Call this from whatever thread you like.
void SetTextBoxText(RichTextBox box, string text)
{
    // Accessing a GUI object from another thread than GUI is not permitted
    //   There are three exceptions to that: InvokeRequired, BeginInvoke, Invoke
    if (box.InvokeRequired)
    // Called from another thread than GUI thread.
    //   Delegate work to GUI thread and exit.
    {
        box.Invoke(new Action<string>(SetTextBoxText), new object[] { box, text });
        return;
    }
    // We're in GUI thread now. Accessing the GUI object is safe.
    box.Text = text;
}


这篇关于控制'richTextBox1'从c#创建的线程以外的线程访问c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 00:32