WebBrowser control in DLL and STAThread error

J

JP2006

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top