无法取消GWT中的重复计时器 [英] Can't cancel repeat timer in GWT
本文介绍了无法取消GWT中的重复计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在GWT中安排一个重复的计时器,它将每毫秒运行一次,轮询某个事件,如果发现令人满意,则执行某些操作并取消计时器。
我试过这样做:
final Timer t = new Timer(){
public void run ){
if(..condition is true,exit){
t.cancel();
doSomething();
}
}
}
t.scheduleRepeating(1);
但是,我收到一条错误消息,如局部变量t可能未被初始化即可。我将这段代码放在 RequestBuilder
回调的 onSuccess
子句中。我该如何实现这一目标?
解决方案
您无法在初始化本身时访问它。
更改您的代码到
final Timer fgf = new Timer(){
@Override
public void run(){
cancel();
System.out.println();
}
};
I am trying to schedule a repeating timer in GWT, it will run every one milli second, poll for a certain event, if it is found satisfactory, do something and cancel the timer. I tried doing this:
final Timer t = new Timer() {
public void run() {
if (..condition is true, exit) {
t.cancel();
doSomething();
}
}
}
t.scheduleRepeating(1);
However, I get an error message like the local variable t may not have been initialized. I am putting tis piece of code in the onSuccess
clause of a RequestBuilder
callback.. How do I achieve this?
解决方案
You cannot access it while intializing itself.
change your code to
final Timer fgf = new Timer() {
@Override
public void run() {
cancel();
System.out.println();
}
};
这篇关于无法取消GWT中的重复计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文