壁虎多线程错误

本文关键字:错误 多线程 壁虎 | 更新日期: 2023-09-27 18:07:39

我正试图使应用程序与5虚拟(隐藏)壁虎(Xulrunner)浏览器。但是,当我试图创建一个浏览器在线程它的返回错误在GeckoPreferences我完全与它混淆!

代码示例:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Skybound.Gecko;
using System.Threading;
namespace Gekco_Test
{
public partial class Main : DevExpress.XtraEditors.XtraForm
{
    public Main()
    {
        InitializeComponent();
        CheckForIllegalCrossThreadCalls = false;
    }
    private void Main_Load(object sender, EventArgs e)
    {
    }
    private void simpleButton1_Click(object sender, EventArgs e)
    {
        Thread th = new Thread(webControllerFunc);
        th.SetApartmentState(ApartmentState.STA);
        th.Start();

    }
    void webControllerFunc()
    {
        geckoWebControl gControll = new geckoWebControl();
        gControll.webBrowserAccess("91.213.108.178", 80);
    }
}
class geckoWebControl
{
    bool readyState;
    GeckoWebBrowser wb = new GeckoWebBrowser();
    public string webBrowserAccess(string host,int port)
    {
        Skybound.Gecko.Xpcom.Initialize(Application.StartupPath + "''xulrunner''");
        readyState = false;
        Form form = new Form();
        GeckoPreferences.User["network.proxy.http"] = host;
        GeckoPreferences.User["network.proxy.http_port"] = port;
        GeckoPreferences.User["network.proxy.type"] = 1;
        wb.Navigate("about:blank");
        wb.DocumentCompleted += wb_DocumentCompleted;
        while (!readyState)
            Application.DoEvents();
        return wb.Document.TextContent;
    }
    void wb_DocumentCompleted(object sender, EventArgs e)
    {
        readyState = true;
    }
}

}

错误:

{"无法强制转换'System '类型的COM对象。__ComObject'到接口类型'Skybound.Gecko.nsIServiceManager'。由于以下错误,COM组件上对IID为'{8BB35ED9-E332-462D-9155-4A002AB5C958}'的接口的QueryInterface调用失败,导致此操作失败:No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)))。"}

谢谢!

壁虎多线程错误

Gecko不支持多线程。因此,您可以使用下面的代码在线程中使用它。

this.BeginInvoke(new Action(() => {
//What you want gecko browser to do! Like:
geckoBrowser.navigate("http://somewhere.com");
 }));