Look at this code:

delegate void SetBrowserContentDelegate(WebBrowser b);

   if (browser.InvokeRequired)
                    browser.Invoke(new SetBrowserContentDelegate(SetBrowserContent), browser);
        browser.DocumentText = "<html><body>example</body></html>";
   //this code here is executed and it gives an error saying this "Cross-thread operation..."

        void SetBrowserContent(WebBrowser b)
            b.DocumentText = message_;

My question is why the SetBrowserContent method is not executed?The exception says that the form(i mean the form where the 'browser' is) is accessed by thread other than the thread it's created on.I'm fairly new to C# programming and this threads and delegates are very obscure to me,i'm doing something wrong but don't know what...Sorry for my bad english.Thanks in advance.

OMG i'm totally confused...the exception is thrown when i try to set DocumentText property of the WebBrowser.If i do something else like changing size,hiding it or something else it works fine.What's wrong with that DocumentText property?If i set the form CheckForIllegalCrossThreasCalls property to false,the application throws an exception but this time is the following "Controls created on one thread cannot be parented to a control on a different thread."When i remove "browser.DocumentText = "bla bla" it doesn't throw an exception!!!

This article has been dead for over six months. Start a new discussion instead.