关于WebBrowser在C#.net2008的console程序中的问题,为什么会报告不在主线程中从而无法初始化?
而我在vb.net 2008中完全没有任何问题。
我的程序非常简单,绝对单线程程序。如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebBrowser wb;
wb = new WebBrowser();
wb.Navigate("about:blank");
}
}
}当运行wb = new WebBrowser();这一句时报错:
Unhandled Exception: System.Threading.ThreadStateException: ActiveX control '885
6f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.但是同样的写法在vb.net中却完全没问题。难道VB和C#对console程序的实现不一样?
而我在vb.net 2008中完全没有任何问题。
我的程序非常简单,绝对单线程程序。如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebBrowser wb;
wb = new WebBrowser();
wb.Navigate("about:blank");
}
}
}当运行wb = new WebBrowser();这一句时报错:
Unhandled Exception: System.Threading.ThreadStateException: ActiveX control '885
6f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.但是同样的写法在vb.net中却完全没问题。难道VB和C#对console程序的实现不一样?
http://topic.csdn.net/u/20090325/16/cca13fb1-5eba-4bf2-b829-43ba1dd487a8.html
[STAThread]//加上这个定义
static void Main()
{
WebBrowser wb;
wb = new WebBrowser();
wb.Navigate("about:blank");
}