1

5 つの仮想 (非表示) Gecko (Xulrunner) ブラウザーでアプリケーションを作成しようとしています。しかし、Threading で 1 つのブラウザーを作成しようとすると、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-462D-9155 を持つインターフェイスの COM コンポーネントで QueryInterface 呼び出しが行われたため、失敗しました。 -4A002AB5C958}' は、次のエラーが原因で失敗しました: No such interface supported (HRESULT からの例外: 0x80004002 (E_NOINTERFACE))"}

ありがとう!

4

1 に答える 1

2

Gecko はマルチスレッドをサポートしていません。したがって、次のコードを使用してスレッドで使用できます。

this.BeginInvoke(new Action(() => {
//What you want gecko browser to do! Like:
geckoBrowser.navigate("http://somewhere.com");
 }));
于 2013-05-30T08:42:48.197 に答える