我試圖使用WebBrowser控件在ASP .NET應用程序:WebBrowser控件
public BrowserForm()
{
webBrowser1 = new WebBrowser();
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
private void webBrowser1_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e)
{
// code here
}
,但得到的錯誤:
'8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment
然後我做了這樣的事情:
public BrowserForm()
{
ThreadStart ts = new ThreadStart(StartThread);
var t = new Thread(ts);
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
[STAThread]
public void StartThread()
{
webBrowser1 = new WebBrowser();
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
[STAThread]
private void webBrowser1_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e)
{
//code here
}
但是它仍然不能滿足我的需求......給我這樣的錯誤:
Error HRESULT E_FAIL has been returned from a call to a COM component
任何工作?我不是線程或COM的專家,但是嘗試將WindowApplication轉換爲WebApplication,它使用網頁的屏幕截圖提供了一個URL。 :(
雖然你問了一個解決方案,但只是在想......一個途徑達到相同的創建ActiveX控件,會做的屏幕截圖的工作,並把它添加到您的ASP.NET應用程序... – 2010-02-24 12:19:28