首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gecko MultiThreading错误

Gecko MultiThreading错误
EN

Stack Overflow用户
提问于 2013-04-06 22:30:46
回答 1查看 2.6K关注 0票数 1

我正在尝试用5个虚拟的(隐藏的) Gecko(Xulrunner)浏览器做一个应用程序。但是当我尝试在GeckoPreferences中创建一个线程返回错误的浏览器时,我完全把它搞糊涂了!

下面是代码示例:

代码语言:javascript
复制
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对象强制转换为接口类型’supported .Gecko.nsIServiceManager‘。此操作失败,因为对接口IID为'{8BB35ED9-E332-462D-9155-4A002AB5C958}’的接口的COM组件上的QueryInterface调用由于以下错误而失败:不支持此类接口(来自HRESULT的异常: 0x80004002 (E_NOINTERFACE))。”}

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-30 16:42:48

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

代码语言:javascript
复制
this.BeginInvoke(new Action(() => {
//What you want gecko browser to do! Like:
geckoBrowser.navigate("http://somewhere.com");
 }));
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15852128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档