进度条仅在调试模式下显示。作业加异步显示

发布于 2024-12-29 23:20:50 字数 548 浏览 0 评论 0原文

 Job job = new Job("Initialize Info ") 
 {

     @Override
     protected IStatus run(IProgressMonitor monitor) {
     //some action in job thread

         Display.getDefault().asyncExec(new Runnable() {

             @Override
             public void run() {
                 //
                 //different actions with UI components.
             }
         });
      return Status.OK_STATUS;
      }
  };
  job.schedule();

当我在调试模式下运行应用程序时,进度条会正确显示,并且所有 UI 组件都在等待作业。但在发布模式下,UI 组件仍在等待作业,但进度条没有反映。

原因是什么?

 Job job = new Job("Initialize Info ") 
 {

     @Override
     protected IStatus run(IProgressMonitor monitor) {
     //some action in job thread

         Display.getDefault().asyncExec(new Runnable() {

             @Override
             public void run() {
                 //
                 //different actions with UI components.
             }
         });
      return Status.OK_STATUS;
      }
  };
  job.schedule();

When I run application in debug mode then progress bar is correctly displayed and all UI components waiting for a job. But in release mode UI components still waiting for a job but progress bar doesn't reflect.

What is the reason?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的鱼塘能养鲲 2025-01-05 23:20:51

您不需要运行 asycExec。尝试使用 UIJob
UIJob 是通过 asyncExec 在 UI 线程内运行的作业。
像这样:

Job job = new Job("") {

    @Override
    protected IStatus run(IProgressMonitor monitor) {
        monitor.beginTask("Task..." -1);
        // do what i need to do (and doesn't bother my UI)
        return Status.OK_STATUS;
    }
};

job.setUser(true);
job.schedule();
job.addJobChangeListener(new JobChangeAdapter() {
    @Override
    public void done(IJobChangeEvent event) {
        new UIJob("") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                // Update my UI
                monitor.beginTask("UI Task..." -1);
                return Status.OK_STATUS;
            }
        }.schedule();
        super.done(event);
    }
});

You don't need to run asycExec. try use UIJob:
The UIJob is a Job that runs within the UI Thread via an asyncExec.
like this:

Job job = new Job("") {

    @Override
    protected IStatus run(IProgressMonitor monitor) {
        monitor.beginTask("Task..." -1);
        // do what i need to do (and doesn't bother my UI)
        return Status.OK_STATUS;
    }
};

job.setUser(true);
job.schedule();
job.addJobChangeListener(new JobChangeAdapter() {
    @Override
    public void done(IJobChangeEvent event) {
        new UIJob("") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                // Update my UI
                monitor.beginTask("UI Task..." -1);
                return Status.OK_STATUS;
            }
        }.schedule();
        super.done(event);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文