必须在主线程上使用Webkit吗? [英] Must Webkit always be used on the main thread?

查看:349
本文介绍了必须在主线程上使用Webkit吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在后台呈现网页,遇到以下问题

I'm trying to render webpages in the background and I ran into the following trouble

2012-05-11 12:39:02.086 [77207:1c03] An uncaught exception was raised
2012-05-11 12:39:02.087 [77207:1c03] objc_object* -[WebView initWithFrame:frameName:groupName:](WebView*, objc_selector*, CGRect, NSString*, NSString*) was called from a secondary thread



我理解webkit类是不是线程安全的,但是它们也必须总是从主线程使用?或者,我可以创建一个虚拟web视图,只是初始化webkit,然后在后台线程使用webkit类。

I understand that webkit classes are not thread-safe, but do they also have to be always used from the main thread? Alternatively, can I create a dummy web view just to initialize webkit and then later use webkit classes from background threads?

推荐答案

WebView NSView 的子类。从线程编程指南


NSView类通常是线程安全的,但有一些例外。
应该只在应用程序的主线程中创建,销毁,调整大小,移动和执行
NSView对象的其他操作。
从辅助线程绘制
线程安全的,只要你支持绘图
调用lockFocusIfCanDraw和unlockFocus。

The NSView class is generally thread-safe, with a few exceptions. You should create, destroy, resize, move, and perform other operations on NSView objects only from the main thread of an application. Drawing from secondary threads is thread-safe as long as you bracket drawing calls with calls to lockFocusIfCanDraw and unlockFocus.

(强调已添加。)

我不太清楚AppKit WebView 是如何工作的,但我的理解是,在UIKit中只有一个 UIWebView ,由于性能原因被重复使用,类似于AppKit中的字段编辑器。如果我的理解是正确的,并且 WebView 的行为类似,我可以看到你有更大的问题背景线程。

I'm less clear on how the AppKit WebView works, but my understanding is that in UIKit there is really only one UIWebView that just gets reused all over for performance reasons, something akin to the field editor in AppKit. If my understanding is correct, and WebView behaves similarly, I could see you having even bigger problems with background threading.

这篇关于必须在主线程上使用Webkit吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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