| Auto Refresh [message #636170] |
Fri, 29 October 2010 10:13  |
MohanVaradharajan Messages: 7 Registered: October 2010 |
Junior Member |
|
|
Hi all,
i would like to know how to refresh the view at scheduled interval ?. what is the best way to implement this functionality ?
here is the scenario :
- user will set auto refresh interval
- once he pressed ok button, current view should be refreshed automatically which involves server communication at the scheduled interval...
thanks for your help..
|
|
|
| Re: Auto Refresh [message #636205 is a reply to message #636170] |
Fri, 29 October 2010 12:01   |
|
One way i could think of..
not sure if this is the best way to do it.
private Runnable refreshTask = null;
private int scheduled_interval = 2000;
private boolean autoRefresh = true;
void scheduleAutoRefresh() {
refreshTask = new Runnable() {
public void run() {
//code to refresh view here
System.out.println("Refreshing view at : " + new Date());
if (autoRefresh) { // a variable to stop the refresh task when the view is disposed or no longer used.
Display.getDefault().timerExec(scheduled_interval, refreshTask);
} else {
System.out.println("Stopped refreshing view at : " + new Date());
}
}
};
Display.getDefault().timerExec(scheduled_interval, refreshTask);
}
Regards,
Prasad
http://marketplace.eclipse.org/user/9964/listings
|
|
|
|
| Re: Auto Refresh [message #636289 is a reply to message #636276] |
Sat, 30 October 2010 09:05   |
|
You can use jobs combined with the timer thread.. i.e., create a job and schedule it at regular intervals using the timer thread .
Inside the job once you are done with the server communication you need to use the display thread again to refresh the view. This approach actually prevents the freezing of UI which might occur during the server communication.
Regards,
Prasad
http://marketplace.eclipse.org/user/9964/listings
|
|
|
|
Powered by
FUDForum. Page generated in 0.01558 seconds