这是我在StackOverflow上的第一个问题(抱歉我的英文).我会尽力解释这个问题.
我有一个带有前景玉应用程序的swt应用程序,其中我有一个进度条来通知应用程序的持续时间.要刷新此进度条,我使用:
if(Display.getCurrent() != null) {
progress.run();
}
else {
sShell.getDisplay().syncExec(progress);
}
进展是:
Runnable progress = new Runnable() {
public void run () {
if (progressBar.isDisposed ())
return;
int percentage= (numStep*100)/maxSteps;
progressBar.setSelection(percentage);
if (numStep >= maxSteps){
label1.setText("The simulation has been completed.");
button.setEnabled(true);
}
}
};
我尝试分析这个Runnable所花费的时间并且它是常量,但是当我分析这一行时sSehll.getDisplay().syncExec(progress)需要不同的时间(从0ms到XXXXms)
我读过这个
syncExec(Runnable runnable) causes the current thread (if it is different than the user interface thread of the display) to wait for the runnable to finish.
但是Runnable是时间常数……
有人可以指导我吗?我不明白为什么有时需要3分钟和其他时间.
谢谢