gpt4 book ai didi

user-interface - 在 Eclipse 插件应用程序中将值从非 UI 线程传递到 UI 线程的最佳实践

转载 作者:行者123 更新时间:2023-12-01 02:58:37 25 4
gpt4 key购买 nike

是否有将值从非 UI 线程传递到 Eclipse 插件应用程序中的 UI 线程的最佳实践/ Shiny 示例?

最佳答案

您可以使用 Display.asyncExec()

To allow background threads to perform operations on objects belonging to the UI-thread, the methods syncExec(Runnable runnable) and asyncExec(Runnable runnable) of Display are used.
These are the only methods in SWT that can be called from any thread.
They allow a runnable to be executed by the UI-thread, - either synchronously, causing the background thread to wait for the runnable to finish, - or asynchronously allowing the background thread to continue execution without waiting for the result.

A runnable that is executed using syncExec() most closely matches the equivalent direct call to the UI operation because a Java method call always waits for the result before proceeding, just like syncExec().



this thread 所示:

I thought all those runnables or threads I give to Display.sync or asyncExec are 'Threads' and they get scheduled by the jvm or something along with the UI thread!
I never knew they are not considered the threads, but only pieces of code executed asynchronously by the UI thread!



这段由 UI 线程异步执行的代码可能是从其他线程访问值(同步访问)的好地方。

请参阅“ How to update a GUI from another thread in Java”作为将值传递给 UI 线程的实际示例。

(注意:在 Swing 中,非 Eclipse 非 SWT 方式是使用 Swing Worker,如 I mentioned a year ago )

关于user-interface - 在 Eclipse 插件应用程序中将值从非 UI 线程传递到 UI 线程的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1836025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com