紧凑框架中的Web浏览器 [英] Webbrowser in compact framework

查看:52
本文介绍了紧凑框架中的Web浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在.NET Compact Framework 3.5项目中使用 WebBrowser 组件.我面临着与此矛盾的信息.

I would like to use a WebBrowser component in a .NET Compact Framework 3.5 project. I am confronted with contradictive information about this.

如果我只是尝试使用它,则会收到以下异常:

If I just try to use it, I get the following exception:

System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
at System.Windows.Forms.WebBrowser..ctor()
at dce.pd.dialogmgr.baseimpl.DialogDeviceImpl.createGui(XmlElement pDialogManagerNode) in C:\sourceview\CS.NETCF.2008\dce\pd\dialogmgr\baseimpl\DialogDeviceImpl.cs:line 362
at dce.pd.dialogmgr.baseimpl.DialogDeviceImpl.init() in C:\sourceview\CS.NETCF.2008\dce\pd\dialogmgr\baseimpl\DialogDeviceImpl.cs:line 118
at dce.pd.dialogmgr.thinimpl.ThinClient.createDeviceImpl() in C:\sourceview\CS.NETCF.2008\dce\pd\dialogmgr\thinimpl\ThinClient.cs:line 82
at dce.pd.dialogmgr.thinimpl.ThinClient.init() in C:\sourceview\CS.NETCF.2008\dce\pd\dialogmgr\thinimpl\ThinClient.cs:line 87
at dce.pd.dialogmgr.thinimpl.ThinClient.form_Load(Object sender, EventArgs e) in C:\sourceview\CS.NETCF.2008\dce\pd\dialogmgr\thinimpl\ThinClient.cs:line 66
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

对我来说,这听起来像我必须将 [STAThread] 指令放入我的 Main 方法中.

To me, this sounds like I have to put the [STAThread] directive to my Main method.

[STAThread]
static void Main()
{
  ...
}

但这不起作用,因为

But that doesn't work neither, because the [STAThread] option is not available in compact framework.. So, the application won't even compile now.

不过,根据Microsoft的文档 WebBrowser 组件可用于紧凑框架项目.甚至还有一些例子.(不幸的是,没有提供完整的代码.)

Nevertheless, according to Microsoft's documentation, the WebBrowser components is available for compact framework project. There are even some examples. (Unfortunately the full code is not provided).

那么,我想念什么?

推荐答案

我终于发现这里出了什么问题.

I finally found what's wrong here.

实际上,上述异常(即 System.Threading.ThreadStateException:ActiveX控件'8856f961-340a-11d0-a96b-00c04fd705a2')无法实例化,因为当前线程不在单线程单元中./code>)仅在我尝试直接在笔记本电脑上运行已编译的可执行文件时显示.

In fact, the exception above (i.e. System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.) only shows up when I try to run the compiled executable directly on my laptop.

模拟器对我不起作用.然后我终于让模拟器开始工作了.我意识到我必须选择一个仿真器"设备,其名称以仿真器"结尾.(例如"Windows Mobile 6模拟器").在测试之前,您需要使用工具栏中的连接到设备"按钮连接这些设备.建立连接后,应用程序实际上可以在模拟器上正常运行.

The simulator wasn't working for me. And I finally got the simulator working now. I realized that I had to select an "emulator" device, the kind that ends with "emulator" in its name. (e.g. "Windows Mobile 6 Emulator"). You need to connect these devices before testing, using the "connect to device" button in the toolbar. Once the connection is made, the application actually runs just fine on the emulator.

问题仍然存在:为什么应用程序不能在模拟器上直接运行,而不能直接在笔记本电脑上运行.但这是一个不同的问题.

The question remains: why doesn't the application run directly on my laptop while it does run fine in an emulator. But that's a different question.

当然,操作系统是不同的.但是我给人的印象是,系统使用的是.NET框架的不同版本.以前我错误地认为所有紧凑型框架应用程序也可以在具有完整功能的.net框架的笔记本电脑上运行.现在看来这是不正确的.

Of course the operating system is different. But I have the impression, that the system uses a different version of the .NET framework. Previously I wrongfully assumed that all compact framework apps could also run on a laptop with the full blown .net framework. Now it appears that this is incorrect.

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

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