WatIn 多线程
如何使用 async
委托与 WatIn 合作?我尝试过,但它返回了这个错误:
CurrentThread 需要将其 ApartmentState 设置为 ApartmentState.STA 能够自动化 Internet Explorer。
How can I work with WatIn using async
delegates? I tried, but it returned this error:
The CurrentThread needs to have it's ApartmentState set to
ApartmentState.STA to be able to automate Internet Explorer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您在委托上使用
BeginInvoke()
。他们使用线程池来做线程工作,线程池中的线程都是MTA的。您必须通过创建自己的线程
以老式方式来完成此操作。线程类提供了方法(GetApartmentState
和SetApartmentState
)来更改公寓模型。我想您可能还需要在您的
线程
中使用自己的消息泵。像这样的事情可能会让你开始:
I assume you use
BeginInvoke()
on your delegates. They use the thread pool to do threaded work and the threads in the thread pool are all MTA's. You will have to do it the old fashion way by creating your ownThread
. The thread class offers methods (GetApartmentState
andSetApartmentState
) to change the apartment model.I guess you might need your own message pump as well in your
thread
.Something like this might get you started:
由于 IE COM 互操作工作方式的本质,它本质上需要在单线程单元中运行。以下内容摘自 [watin.org] 页面上有关该主题的内容1
Because of the nature of how the IE COM interop works, it inherently needs to be run in a single-threaded apartment. The following is copied from the [watin.org] page on the subject1
从 NUnit 2.5 开始,使用 RequiresSTA 属性。
编辑
从 NUnit 3.0 开始,使用 Apartment 属性。
Use RequiresSTA attribute, starting with NUnit 2.5.
EDIT
Use Apartment attribute, starting with NUnit 3.0.