且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

必须在主线程上使用Webkit吗?

更新时间:2023-02-14 20:11:30

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.