# 不及格的程序员-八神

posts - 173,  comments - 1172,  trackbacks - 0

The HTML importer should not be called from a background thread (that is, the options dictionary includesNSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out. Calling it from the main thread works (but can still time out if the HTML contains references to external resources, which should be avoided at all costs). The HTML import mechanism is meant for implementing something like markdown (that is, text styles, colors, and so on), not for general HTML import.

Multicore considerations:

Since OS X v10.4, NSAttributedString has used WebKit for all import (but not for export) of HTML documents. Because WebKit document loading is not thread safe, this has not been safe to use on background threads. For applications linked on OS X v10.5 and later, if NSAttributedString imports HTML documents on any but the main thread, the use of WebKit is transferred to the main thread via performSelectorOnMainThread:withObject:waitUntilDone:. This makes the operation thread safe, but it requires that the main thread be executing the run loop in one of the common modes. This behavior can be overridden by setting the value of the standard user default NSRunWebKitOnAppKitThread to either YES(to obtain the new behavior regardless of linkage) or NO (to obtain the old behavior regardless of linkage).

posted on 2014-02-20 09:42 不及格的程序员-八神 阅读(...) 评论(...) 编辑 收藏