2012-01-30 87 views
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組件仍然在等待作業,但進度條並未反映出來。進度條僅在調試模式下顯示。作業加異步顯示

是什麼原因?

回答

1

您不需要運行asycExec。嘗試使用UIJob
The UIJob is a Job that runs within the UI Thread via an asyncExec.
這樣的:

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); 
    } 
}); 
+0

的感謝!它幫助! – Volad 2012-01-31 19:08:19