如果工作台空闲一段时间,我想“注销”或“关闭”应用程序 时间量(30分钟等),但我还不知道如何实现。有人有什么建议吗?
最佳答案
我有一个类似的要求,我绞尽脑汁去实现它。
要求:
Lock the Application Window, if idle for some pre-configured amount of time.
但是,我的是一个纯 SWT 应用程序
,我可以完全控制 Create
和 Dispose
Shell
PFB 是我的代码的摘录,有详细的文档记录,它可能会对您有所帮助或为您提供见解。
//Boilerplate code for SWT Shell
//Event loop modified in our case
boolean readAndDispatch;
while (!shell.isDisposed()) { //UI Thread continuously loop in Processing and waiting for Events until shell is disposed.
try {
readAndDispatch = shell.getDisplay().readAndDispatch(); // reads an Event and dispatches, also returns true if there is some work else false.
if (!readAndDispatch) { //There is no work to do, means, System is idle
timer.schedule(worker, delay); // So, schedule a Timer which triggers some work(lock or logout code) after specified time(delay)
shell.getDisplay().sleep();
} else{
timer.reschedule(delay); //This means System is not idle. So, reset your Timer
}
} catch (Throwable e) {
log.error(ExceptionUtils.getStackTrace(e));
MessageDialog.openError(shell, "Error !!", ExceptionUtils.getRootCauseMessage(e));
}
}
注意
我有一个 java.util.Timer
的自定义实现,通过取消现有的 TimerTask
来提供重新安排功能,创建一个新的 Timertask
然后再次安排。
关于java - 如何在 RCP 应用程序/SWT 中实现超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17375343/