关于Web浏览器和多线程的AccessViolationException [英] About AccessViolationException with Webbrowser and Multi-Thread

查看:154
本文介绍了关于Web浏览器和多线程的AccessViolationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题。我有一个基于项目的多线程。所有线程都有webbrowser控件。

该项目在单线程上运行正常。但是当我尝试在多线程上工作时,我得到了AccessViolationException。有document.GetElementById();抛出异常的表达式。有没有人有想法?

Hi,I have a problem. I have a project based multi-thread. All threads have webbrowser control.
The project works fine on single thread. But when i am trying to work on multi-thread, i get AccessViolationException. There is "document.GetElementById();" expression on line of exception thrown. Does anyone have an idea?

推荐答案

你不能在UI(启动)线程以外的任何线程上使用或创建webbrowser控件的实例。



您也无法以任何方式触摸任何除UI线程之外的任何形式的控件。



如果必须在其他线程的UI控件上设置属性和调用方法,则必须在UI线程上调用方法来执行此操作。



C#调用UI线程上的方法 [ ^ ]
You cannot use nor create instances of the webbrowser control on any thread other than the UI (startup) thread.

You also cannot touch, in any way at all, any control on a form from anything other than the UI thread.

If you must set properties and call methods on UI controls from other threads you have to Invoke methods on the UI thread to do so.

C# Invoke method on UI thread[^]


这篇关于关于Web浏览器和多线程的AccessViolationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆