troubleshooting Question

Starting second form in new thread

Avatar of dbtoth
dbtoth asked on
.NET ProgrammingC#
10 Comments1 Solution20158 ViewsLast Modified:
Here's the situation... I've got a VS.2005 C# WinForms application in which I needed a way to display a powerpoint PPS or a MSWord document inside a form window... after a very large amount of searching and a lot of dead ends I determined the only way this was going to work was to place an IE browser control on the form in question.

The general idea is that the second monitor (which faces the customers) will spew advertising until display of a specific document is required, then I swap the PPS for the word doc in the IE Browser

I display this form maximized on the secondary monitor. This part worked OK...

            // Launch the secondary screen window
            SecondScreen ss = new SecondScreen();
            this.secondScreen = ss;

            // Now start the main window

For this most part this works OK, until the PPS hits a slide transition, then my main application form mainForm has a mouse and keyboard hiccup until the transition finishes on the slide. This is annoying as hell, particularly when you are trying to type.

I figured I could get around this by trying to launch the new secondScreen form on it's own thread, then it wouldn't interfere with me anymore. It sounded like a good idea at the time...

        private void showSecondScreen()
            SecondScreen ss = new SecondScreen();
            this.secondScreen = ss;

and then in my main form load event...

            // Start the second screen
            Thread sf= new Thread(new ThreadStart(showSecondScreen));

when the SecondScreen form launches I get an exception error from the AXWebBrowser control...

ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.

Searching for this message resulted in recommendations to set [STAThread] on the main() function. Obviously there's no main() inside the SecondScreen form and the main() in MainForm already has [STAThread] set by the designer.

Any suggestions how I can launch this other window on it's own thread so it's processing doesn't interfere with my main application or some other means of keeping the IE Browser control from messing up the main form?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros