473,320 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Wierd threading issues with WebBrowser control

I don't understand what's going on in the following program. I believe it
should simply create a form with a browser in it and navigate that browser to
Google. However, the constructor for the WebBrowser is throwing a
ThreadStateException saying ActiveX control
'8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the
current thread is not in a single-threaded apartment. Any ideas what's going
on?

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Project1
{
class Class1
{
public static void Main()
{
Application.Run(new Form1());
}
}

class Form1 : Form
{
public Form1()
{
WebBrowser b = new WebBrowser();
b.Navigate("www.google.com");
this.Controls.Add(b);
}
}
}

Thanks
-Warren
Aug 17 '05 #1
2 14433
Warren <Wa****@discussions.microsoft.com> wrote:
I don't understand what's going on in the following program. I believe it
should simply create a form with a browser in it and navigate that browser to
Google. However, the constructor for the WebBrowser is throwing a
ThreadStateException saying ActiveX control
'8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the
current thread is not in a single-threaded apartment. Any ideas what's going
on?


It means exactly what it says - you're not running in an STA. If you
put the [STAThread] attribute on your Main method, you should be fine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 17 '05 #2
"Jon Skeet [C# MVP]" wrote:
Warren <Wa****@discussions.microsoft.com> wrote:
I don't understand what's going on in the following program. I believe it
should simply create a form with a browser in it and navigate that browser to
Google. However, the constructor for the WebBrowser is throwing a
ThreadStateException saying ActiveX control
'8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the
current thread is not in a single-threaded apartment. Any ideas what's going
on?


It means exactly what it says - you're not running in an STA. If you
put the [STAThread] attribute on your Main method, you should be fine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Thanks a bunch! I'd seen that on Windows Forms Designer generated code, but
never had any idea what it did.
Aug 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vetrivel | last post by:
Application architecture : Develop interface between two existing systems, a. Enterprise CRM system b. Web based intranet system. Environment : Intranet Server : IIS and ASP. Script :...
1
by: boxim | last post by:
Hi All, Just after some other opinions really.... We're writing this application that in places implements the WebBrowser control to make certain bits look nicer as well as make things quicker...
0
by: omyek | last post by:
Heh, I know some of you have read the subject and are wondering what in the heck I'm doing. Well, for all intensive purposes, I've had to embed a WebBrowser control into a DLL and reference that...
2
by: Warren | last post by:
I don't understand what's going on in the following program. I believe it should simply create a form with a browser in it and navigate that browser to Google. However, the constructor for the...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
1
by: JP2006 | last post by:
Getting a an error with my DLL stating that my control 'cannot be instantiated because the current thread is not in a single-threaded apartment.' The code is: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
1
by: Narasimham | last post by:
Hi, I am trying to use the webbrowser control in the compact framework. I am setting a URL to the webbrowser control and am able to see the page in my handheld device. I have two issues 1. I...
1
by: JP2006 | last post by:
I'm trying to write a control that will take a screen capture of a particular website when a user submits a form in a web application; one of the form fields is for a URL - the control needs to get...
17
by: Cesar | last post by:
Hello people. I'm having a Winform app that contains a webbrowser control that keeps navigating from one page to another permanentrly to make some tests. The problem I'm having is that after a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.