473,419 Members | 1,565 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,419 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 14440
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.