469,599 Members | 2,700 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,599 developers. It's quick & easy.

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 2083
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Selden McCabe | last post: by
6 posts views Thread by Shane Story | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.