【问题标题】:Gecko MultiThreading ErrorGecko 多线程错误
【发布时间】:2013-05-30 19:13:29
【问题描述】:

我正在尝试使用 5 个虚拟(隐藏)Gecko(Xulrunner)浏览器制作应用程序。但是当我尝试在 Threading 中创建一个浏览器时,它在 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.__ComObject”的 COM 对象转换为接口类型“Skybound.Gecko.nsIServiceManager”。此操作失败,因为 IID 为“{8BB35ED9-E332-”接口的 COM 组件上的 QueryInterface 调用462D-9155-4A002AB5C958}' 由于以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE))。"}

谢谢!

【问题讨论】:

    标签: c# gecko


    【解决方案1】:

    Gecko 不支持多线程。所以你可以使用它下面的代码在线程中使用它。

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

    【讨论】:

      猜你喜欢
      • 2015-01-20
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      相关资源
      最近更新 更多