软件编程
位置:首页>> 软件编程>> java编程>> Java开发中可以防止界面假死的刷新代码

Java开发中可以防止界面假死的刷新代码

作者:李灿辉  发布时间:2023-11-23 22:23:41 

标签:java,thread,exception

代码如下:


try {
 // 创建一个线程
 Thread thread = new Thread() {
 public void run() {
  int i = 0;
  while(true){
  final long start = System.currentTimeMillis();
  try {
   Thread.sleep(1);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  final int a = i;
  if (!Display.getDefault().isDisposed()) {
   Runnable runnable = new Runnable() {
   public void run() {
    processModel.setProcessName(start + "---" + a);
   }
   };
   Display.getDefault().syncExec(runnable);
  }
  i++;
  }
 }
 };
 thread.start();
} catch (Exception e) {
 e.printStackTrace();
}

来源:https://blog.csdn.net/li_canhui/article/details/7057212

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com