locked
A web browser within console tab RRS feed

  • Question

  • Hi, everyone,

    I design a tab for showing in Windows Home Server Colsole program. 

    I'd like to show a tab that function is while clicking it and the panel under the tab will show a web page.

    I encounter a problem while I add a user control containning a webBrowser control.

    But when I start the console problem, the tab is disappeared.

    It's seem to not support this kinds of control (webBrowser)??

    I try to use the other control such like button, label, textbox, they all can work while I click my designed tab.

    Have someone meet this problem before?

    Or, any idea for this problem.

    Thanks a lot,

    jim
    Tuesday, September 23, 2008 8:30 AM

Answers

  • Hi!

    I also came across this problem when I was working for one of my Add-Ins.

    The problem is that the System.Windows.Forms.WebBrowser Control actually wraps the ActiveX axWebBrowser and therefore the thread that is instantiating the control has to be in a Single-Thread-Apartment (STA) while the Console is in a Multi-Thread-Apartment (MTA).

    The only solution I have found so far is to instantiate the control when the TabControl is retrieved by the Console:

        private System.Windows.Forms.WebBrowser browser = null;   
     
        public Control TabControl   
        {   
            get   
                {   
                    InitBrowser();   
                    return tabControl;   
                }   
        }  
     
        void InitBrowser()  
        {  
            if (browser == null)  
                {  
                    browser = new System.Windows.Forms.WebBrowser();  
                    browser.Left = 0;  
                    browser.Top = 31;  
                    browser.Width = this.width;  
                    browser.Height = this.height - 31;  
     
                    tabControl.Controls.Add(browser);  
                }  
     
       } 

    Let me know if this helps ;)

    Best regards, Alex
    • Marked as answer by S21Jim Wednesday, October 1, 2008 5:24 PM
    Sunday, September 28, 2008 10:15 AM

All replies

  • Check the WHS Logs, guessing a programming error on your side? Can you post code?
    Also are you using the .NET System.Windows.Forms.WebBrowser or the AxtiveX axWebBrowser?
    I would assume the ActiveX web browser to work for sure.
    Thursday, September 25, 2008 2:39 AM
    Moderator
  • Hi!

    I also came across this problem when I was working for one of my Add-Ins.

    The problem is that the System.Windows.Forms.WebBrowser Control actually wraps the ActiveX axWebBrowser and therefore the thread that is instantiating the control has to be in a Single-Thread-Apartment (STA) while the Console is in a Multi-Thread-Apartment (MTA).

    The only solution I have found so far is to instantiate the control when the TabControl is retrieved by the Console:

        private System.Windows.Forms.WebBrowser browser = null;   
     
        public Control TabControl   
        {   
            get   
                {   
                    InitBrowser();   
                    return tabControl;   
                }   
        }  
     
        void InitBrowser()  
        {  
            if (browser == null)  
                {  
                    browser = new System.Windows.Forms.WebBrowser();  
                    browser.Left = 0;  
                    browser.Top = 31;  
                    browser.Width = this.width;  
                    browser.Height = this.height - 31;  
     
                    tabControl.Controls.Add(browser);  
                }  
     
       } 

    Let me know if this helps ;)

    Best regards, Alex
    • Marked as answer by S21Jim Wednesday, October 1, 2008 5:24 PM
    Sunday, September 28, 2008 10:15 AM
  • Hi, Alex,

    Thanks for your assistance.

    It can work now.

    Your information is very useful for me.

    I'd like to ask you how you know the home server console tab is MTA.

    What is difference between MTA and STA to add the web browser control into the console tab?

    Could you give me more info?

    Thanks,
     
    Jim.
    Wednesday, October 1, 2008 4:35 PM
  • Hi!

    I actually don't know if the Console is STA or MTA, but that doesn't matter. The problem is, that you are accessing the Control from a different thread than the one which created the Control, and this isn't allowed (as with many other native COM-objects). Remember that the .NET Framework creates various threads when you start an application (e.g. the GUI-thread), even if you didn't create these threads in your code.

    Here is a good explanation of the difference between STA and MTA: http://bytes.com/forum/post1049185-3.html

    Regards, Alex
    Friday, October 3, 2008 2:12 PM