Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends. i'm retreiving data from the richTextBox
C#

. but i got above error.how can i solve this
Posted
Comments
F-ES Sitecore 22-Jan-16 3:46am    
Have you googled the error? Only the main GUI thread can access GUI controls. If you want code on a different thread to update a control you need to use the Invoke method to do so. Google the error you're have and you'll find lots of examples.

1 solution

Delegate the UI handling to the thread that created the UI object. That is usually the main thread, a.k.a. GUI thread.
C#
// 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;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900