multithreading - Webkit 必须始终在主线程上使用吗?

标签 multithreading cocoa webkit

我尝试在后台渲染网页,但遇到了以下问题

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 View 来初始化 webkit,然后在后台线程中使用 webkit 类吗?

最佳答案

WebViewNSView 的子类。来自Threading Programming Guide :

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 的行为类似,我可以看到您在后台线程方面遇到了更大的问题。

关于multithreading - Webkit 必须始终在主线程上使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555403/

相关文章:

javascript - INVALID_STATE_ERR : DOM Exception 11 (WebKit)

multithreading - 原子的 Clojure 原子派生和重置

objective-c - 调用 [NSScreen mainScreen] 时的额外线程

jquery-mobile - changePage “jumps”返回旧页面

objective-c - 10.5 中的 IOBluetoothHostContoller

macos - 从 Mac 发送 iMessage

javascript - Qt编程: How to use custom data type in QVariantMap?

multithreading - 单元测试多线程应用程序

java - 单例中的双重检查锁定

c++ - OpenMP:一次为线程分配一个迭代