473,382 Members | 1,396 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,382 software developers and data experts.

WebBrowser control in DLL and STAThread error

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:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace xCapture
{
public class xcap
{
static void Main()
{
Thread newThread = new Thread(new ThreadStart(createXCap));
newThread.SetApartmentState(ApartmentState.STA);
}

public static void createXCap()
{
WebBrowser wb = new WebBrowser();
wb.Visible = false;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It fails on the line - WebBrowser wb = new WebBrowser();

Have tried setting [STAThread] on the main method also to no avail.
Any ideas?

Sep 8 '06 #1
1 2167
I guess you gotta use WebBrowser control in UI thread.

JP2006 wrote:
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:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace xCapture
{
public class xcap
{
static void Main()
{
Thread newThread = new Thread(new ThreadStart(createXCap));
newThread.SetApartmentState(ApartmentState.STA);
}

public static void createXCap()
{
WebBrowser wb = new WebBrowser();
wb.Visible = false;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It fails on the line - WebBrowser wb = new WebBrowser();

Have tried setting [STAThread] on the main method also to no avail.
Any ideas?
Sep 8 '06 #2

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

Similar topics

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...
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...
10
by: Selden McCabe | last post by:
I'm trying to display some HTML on a form in a VB.Net project. I've referenced the COM WebBrowser control, and put an instance of it on my form. But during the Form_Load, I'm getting the...
6
by: Shane Story | last post by:
I am trying to add the Microsoft Web Browseractive X control to a vb.net form. I always get an error on the EndInit line. Parts of the errors says: "Unknown error" "First Chance...
2
by: cweeks78681 | last post by:
I am porting some VB6 code that automates navigation through a web page by getting all the <a> tags into a collection and then calling the Click method on the appropriate one. How do I click a...
4
by: dennijr | last post by:
sry its long, questions in the last sentance if u wanna jump to it. i just decided that i would include everything that led up to the problem i made a gif video that i wanted to put...
4
by: David | last post by:
I'm using the AxSHDocVw.WebBrowser control to download data from a webpage at work (it's an internal page on my company's intranet). The page produces a runtime error after a while and the...
3
by: Dom | last post by:
I have a prgram with a webBrowser control. The user can click on a Linked Reference and the webBrowser control shows that site. Sometimes the URL (not my program, but the URL I am browsing to)...
4
by: kimiraikkonen | last post by:
Hi, Just to test, i placed a simple webbrowser to login a site, this site has no problems and has same error with IE6 SP2 but it's suppressed as well and no problem with Firefox browser, but using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.