且构网

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

为什么必须始终从UI线程创建/更新UI元素?

更新时间:2023-11-05 19:26:16

它是由图形框架强加的-它通常(但并非总是)由操作系统提供.

It's imposed by the graphics framework - which is often (but not always) supplied by the operating system.

基本上,将所有内容设置为适当的线程安全"是无效的.虽然不得不封送回UI线程的确很痛苦,但它允许UI线程本身非常快速地处理事件,而不必担心锁定等.

Basically, making everything "properly threadsafe" is inefficient. While it's certainly a pain to have to marshal calls back to the UI thread, it allows the UI thread itself to process events extremely quickly without having to worry about locking etc.