如果在单独的线程中启动,为什么 GeckoFX Navigate() 请求不起作用?

发布于 2024-08-08 18:26:28 字数 439 浏览 4 评论 0原文

为什么这个有效,

    private void buttonBoo_Click(object sender, EventArgs e)
    {
        GeckoBrowser.Navigate("http://www.google.com/");
    }

而这个无效?

    private void buttonBoo_Click(object sender, EventArgs e)
    {
        Thread thread = new Thread(delegate()
        {
            GeckoBrowser.Navigate("http://www.google.com/");
        });

        thread.Start();
    }

Why does this work,

    private void buttonBoo_Click(object sender, EventArgs e)
    {
        GeckoBrowser.Navigate("http://www.google.com/");
    }

and this not?

    private void buttonBoo_Click(object sender, EventArgs e)
    {
        Thread thread = new Thread(delegate()
        {
            GeckoBrowser.Navigate("http://www.google.com/");
        });

        thread.Start();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虐人心 2024-08-15 18:26:28

GeckoBrowser 是一个 Windows 窗体控件。控件的属性和方法只能从创建控件的线程中调用。要从另一个线程对 Control 执行任何操作,您需要使用 Invoke 或 BeginInvoke 方法,例如

Thread thread = new Thread(delegate()
{
  Action<string> action = url => GeckoBrowser.Navigate(url);
  GeckoBrowser.Invoke(action, new object[] { "http://www.google.com/" });
});

GeckoBrowser is a Windows Forms Control. A Control's properties and methods may be called only from the thread on which the Control was created. To do anything with a Control from another thread, you need to use the Invoke or BeginInvoke method, e.g.

Thread thread = new Thread(delegate()
{
  Action<string> action = url => GeckoBrowser.Navigate(url);
  GeckoBrowser.Invoke(action, new object[] { "http://www.google.com/" });
});
星星的轨迹 2024-08-15 18:26:28

请记住,由于底层引擎 XulRunner (XPCOM),GeckoFX 组件通常不是多线程的。这是因为 XulRunner 本身是一个单线程运行时。

Keep in mind that due to the underlying engine, XulRunner (XPCOM), the GeckoFX component is NOT generally multithreadable. This is because XulRunner, itself, is a single threaded runtime.

白衬杉格子梦 2024-08-15 18:26:28

它不起作用,因为 Geckofx 本身不支持跨线程,如果您想要跨线程,您需要先调用它。

    Thread thread = new Thread(delegate()
    {
         this.Invoke(new Action(() => {GeckoBrowser.Navigate("http://www.google.com/");}));
    });

It does not work because Geckofx in itself doesn't support cross Threading if you want to do cross thread you will need to Invoke it first.

    Thread thread = new Thread(delegate()
    {
         this.Invoke(new Action(() => {GeckoBrowser.Navigate("http://www.google.com/");}));
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文